mirror of
https://github.com/gSpotx2f/luci-app-internet-detector.git
synced 2025-12-06 03:26:50 +03:00
mod_email: minor improvements.
This commit is contained in:
@@ -55,9 +55,9 @@ i18n-ru:
|
|||||||
|
|
||||||
**Dependences:** mailsend.
|
**Dependences:** mailsend.
|
||||||
|
|
||||||
wget --no-check-certificate -O /tmp/internet-detector-mod-email_1.5.1-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector-mod-email_1.5.1-r1_all.ipk
|
wget --no-check-certificate -O /tmp/internet-detector-mod-email_1.5.1-r2_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector-mod-email_1.5.1-r2_all.ipk
|
||||||
opkg install /tmp/internet-detector-mod-email_1.5.1-r1_all.ipk
|
opkg install /tmp/internet-detector-mod-email_1.5.1-r2_all.ipk
|
||||||
rm /tmp/internet-detector-mod-email_1.5.1-r1_all.ipk
|
rm /tmp/internet-detector-mod-email_1.5.1-r2_all.ipk
|
||||||
service internet-detector restart
|
service internet-detector restart
|
||||||
|
|
||||||

|

|
||||||
|
|||||||
@@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk
|
|||||||
|
|
||||||
PKG_NAME:=internet-detector-mod-email
|
PKG_NAME:=internet-detector-mod-email
|
||||||
PKG_VERSION:=1.5.1
|
PKG_VERSION:=1.5.1
|
||||||
PKG_RELEASE:=1
|
PKG_RELEASE:=2
|
||||||
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/luci-app-internet-detector>
|
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/luci-app-internet-detector>
|
||||||
|
|
||||||
include $(INCLUDE_DIR)/package.mk
|
include $(INCLUDE_DIR)/package.mk
|
||||||
|
|||||||
@@ -27,12 +27,14 @@ local Module = {
|
|||||||
mailSmtp = nil,
|
mailSmtp = nil,
|
||||||
mailSmtpPort = nil,
|
mailSmtpPort = nil,
|
||||||
mailSecurity = "tls",
|
mailSecurity = "tls",
|
||||||
msgTextPattern = "[%s] (%s) | %s", -- Message (host, instance, message)
|
msgTextPattern = "[%s] (%s) @ %s", -- Message (host, instance, message)
|
||||||
msgSubPattern = "%s notification", -- Subject (host)
|
msgSubPattern = "%s notification", -- Subject (host)
|
||||||
msgConnectPattern = "Internet connected: %s",
|
msgConnectPattern = "Connected: %s",
|
||||||
msgDisconnectPattern = "Internet disconnected: %s",
|
msgDisconnectPattern = "Disconnected: %s",
|
||||||
msgSeparator = "; ",
|
msgSeparator = " | ",
|
||||||
msgMaxItems = 50,
|
msgMaxItems = 50,
|
||||||
|
msgSendAttempts = 3,
|
||||||
|
msgSendTimeout = 5,
|
||||||
status = nil,
|
status = nil,
|
||||||
_enabled = false,
|
_enabled = false,
|
||||||
_deadCounter = 0,
|
_deadCounter = 0,
|
||||||
@@ -42,6 +44,8 @@ local Module = {
|
|||||||
_msgSentConnect = true,
|
_msgSentConnect = true,
|
||||||
_connected = true,
|
_connected = true,
|
||||||
_msgBuffer = {},
|
_msgBuffer = {},
|
||||||
|
_msgSendCounter = 3,
|
||||||
|
_msgTimeoutCounter = 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
function Module:init(t)
|
function Module:init(t)
|
||||||
@@ -94,6 +98,8 @@ function Module:init(t)
|
|||||||
self.syslog("warning", string.format(
|
self.syslog("warning", string.format(
|
||||||
"%s: Insufficient data to connect to the SMTP server", self.name))
|
"%s: Insufficient data to connect to the SMTP server", self.name))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self._msgSendCounter = self.msgSendAttempts
|
||||||
end
|
end
|
||||||
|
|
||||||
function Module:appendNotice(str)
|
function Module:appendNotice(str)
|
||||||
@@ -108,6 +114,7 @@ function Module:appendNotice(str)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Module:sendMessage(msg, textPattern)
|
function Module:sendMessage(msg, textPattern)
|
||||||
|
local retVal = 1
|
||||||
local verboseArg = ""
|
local verboseArg = ""
|
||||||
local emailMsg = string.format(
|
local emailMsg = string.format(
|
||||||
textPattern, self.hostAlias, self.config.serviceConfig.instance, msg)
|
textPattern, self.hostAlias, self.config.serviceConfig.instance, msg)
|
||||||
@@ -139,13 +146,17 @@ function Module:sendMessage(msg, textPattern)
|
|||||||
self.syslog("debug", string.format("%s: %s", self.name, mtaCmd))
|
self.syslog("debug", string.format("%s: %s", self.name, mtaCmd))
|
||||||
end
|
end
|
||||||
|
|
||||||
if os.execute(mtaCmd) ~= 0 then
|
retVal = os.execute(mtaCmd)
|
||||||
self.syslog("err", string.format(
|
if retVal == 0 then
|
||||||
"%s: An error occured while sending message", self.name))
|
|
||||||
else
|
|
||||||
self.syslog("info", string.format(
|
self.syslog("info", string.format(
|
||||||
"%s: Message sent to %s", self.name, self.mailRecipient))
|
"%s: Message sent to %s", self.name, self.mailRecipient))
|
||||||
|
self._msgBuffer = {}
|
||||||
|
else
|
||||||
|
self.syslog("err", string.format(
|
||||||
|
"%s: An error occured while sending message", self.name))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return retVal
|
||||||
end
|
end
|
||||||
|
|
||||||
function Module:run(currentStatus, lastStatus, timeDiff, timeNow, inetChecked)
|
function Module:run(currentStatus, lastStatus, timeDiff, timeNow, inetChecked)
|
||||||
@@ -164,8 +175,7 @@ function Module:run(currentStatus, lastStatus, timeDiff, timeNow, inetChecked)
|
|||||||
|
|
||||||
if not self._msgSentDisconnect and (self.mode == 1 or self.mode == 2) then
|
if not self._msgSentDisconnect and (self.mode == 1 or self.mode == 2) then
|
||||||
if self._deadCounter >= self.deadPeriod then
|
if self._deadCounter >= self.deadPeriod then
|
||||||
self:sendMessage(table.concat(self._msgBuffer, self.msgSeparator), self.msgTextPattern)
|
self._msgSendCounter = 0
|
||||||
self._msgBuffer = {}
|
|
||||||
self._msgSentDisconnect = true
|
self._msgSentDisconnect = true
|
||||||
else
|
else
|
||||||
self._deadCounter = self._deadCounter + timeDiff
|
self._deadCounter = self._deadCounter + timeDiff
|
||||||
@@ -184,8 +194,7 @@ function Module:run(currentStatus, lastStatus, timeDiff, timeNow, inetChecked)
|
|||||||
|
|
||||||
if not self._msgSentConnect and (self.mode == 0 or self.mode == 2) then
|
if not self._msgSentConnect and (self.mode == 0 or self.mode == 2) then
|
||||||
if self._aliveCounter >= self.alivePeriod then
|
if self._aliveCounter >= self.alivePeriod then
|
||||||
self:sendMessage(table.concat(self._msgBuffer, self.msgSeparator), self.msgTextPattern)
|
self._msgSendCounter = 0
|
||||||
self._msgBuffer = {}
|
|
||||||
self._msgSentConnect = true
|
self._msgSentConnect = true
|
||||||
else
|
else
|
||||||
self._aliveCounter = self._aliveCounter + timeDiff
|
self._aliveCounter = self._aliveCounter + timeDiff
|
||||||
@@ -193,6 +202,23 @@ function Module:run(currentStatus, lastStatus, timeDiff, timeNow, inetChecked)
|
|||||||
end
|
end
|
||||||
self._disconnected = false
|
self._disconnected = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if self._msgSendCounter < self.msgSendAttempts then
|
||||||
|
if self._msgTimeoutCounter >= self.msgSendTimeout then
|
||||||
|
if #self._msgBuffer > 0 then
|
||||||
|
if self:sendMessage(table.concat(self._msgBuffer, self.msgSeparator), self.msgTextPattern) == 0 then
|
||||||
|
self._msgSendCounter = self.msgSendAttempts
|
||||||
|
else
|
||||||
|
self._msgSendCounter = self._msgSendCounter + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
self._msgTimeoutCounter = 0
|
||||||
|
else
|
||||||
|
self._msgTimeoutCounter = self._msgTimeoutCounter + timeDiff
|
||||||
|
end
|
||||||
|
else
|
||||||
|
self._msgTimeoutCounter = self.msgSendTimeout
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Module:onExit()
|
function Module:onExit()
|
||||||
|
|||||||
Reference in New Issue
Block a user