Nagios, NRPE scripts.
Nagios, NRPE scripts.
These scripts are used with NRPE and Nagios to allow monitoring of queued items, number of connections (IMAP, POP3, and SMTP). There are 4 scripts that perform the various functions. The hmail_info.vbs just displays information about hMail and isn't used by the NRPE service.
- Attachments
-
- hMailServer_Nagios_NRPE.zip
- Zipped Files.
- (3.03 KiB) Downloaded 1107 times
Re: Nagios, NRPE scripts.
WOO! Very nice! Should prove handy.
In particular the alert if queue gets too big could show abuse by spammer (open relay, hacked account etc), stuck messages, etc.
Thanks!
Bill

Thanks!
Bill
hMailServer build LIVE on my servers: 5.4-B2014050402
#hmailserver on FreeNode IRC https://webchat.freenode.net/?channels=#hmailserver
*** ABSENT FROM hMail! Those in IRC know how to find me if urgent. ***
#hmailserver on FreeNode IRC https://webchat.freenode.net/?channels=#hmailserver
*** ABSENT FROM hMail! Those in IRC know how to find me if urgent. ***
Re: Nagios, NRPE scripts.
Now, I'm guessing here, Nagios would recieve this information via System Log file / SNMP, am I right?
Thanks!!!
-D
-D
Re: Nagios, NRPE scripts.
Yes, No, Maybe. Nagios does a lot.... This script was designed to be used with NRPE (Nagios Remote Plug-In Executor.)
http://www.nagios.org
http://www.nagios.org
Re: Nagios, NRPE scripts.
can anyone verify? I'm currently using a third party company, EM7, for monitoring and ticketing...fun stuff.
Just curious to know if this would work over SNMP
Just curious to know if this would work over SNMP
Thanks!!!
-D
-D
Re: Nagios, NRPE scripts.
These scripts won't directly work over SNMP.
Re: Nagios, NRPE scripts.
I am about to post up a stand-alone version of the queue script that sends email when queue is above the limit. (Presumably run from task scheduler) Otherwise you'd need to modify it for your needs.
Bill
Bill
hMailServer build LIVE on my servers: 5.4-B2014050402
#hmailserver on FreeNode IRC https://webchat.freenode.net/?channels=#hmailserver
*** ABSENT FROM hMail! Those in IRC know how to find me if urgent. ***
#hmailserver on FreeNode IRC https://webchat.freenode.net/?channels=#hmailserver
*** ABSENT FROM hMail! Those in IRC know how to find me if urgent. ***
Re: Nagios, NRPE scripts.
OK here is a very basic script based on rolaids0 queue script posted above that does not require Nagios to email alert if set queue size is passed:
Odds are you'd run it on a given interval using Task Scheduler but get it working from CMD prompt 1st.
Or call this from a monitoring tool & check the return code. 0 is OK, 1 is warning, 3 is error.
Should be simple to use the oMessage stuff in this script to modify the other scripts or add the needed portions here if desired.
Bill
Code: Select all
Option Explicit
On Error Resume Next
'This script sends email alert when queue above defined limit
'Original by rolaids0 - "Nagios, NRPE scripts."
'administrator information
Const AdminUser = "hmail_admin_username"
Const AdminPassword = "hmail_admin_password"
Const WarnCount = 5
Const FromEmail = "server@yourdomain.tld"
Const ToName = "Admin"
Const ToEmail = "admin@somedomain.tld"
'don't edit below
Dim oApp: Set oApp = CreateObject("hMailServer.Application")
Call oApp.Authenticate(AdminUser,AdminPassword)
oApp.Connect
'catch connection errors
If Err.Number <> 0 Then
WScript.StdOut.Write "Error connecting!"
WScript.Quit 3
End If
Dim QueueCount: QueueCount = 0
Dim OutPut
Dim oStat: Set oStat = oApp.Status
Dim TempStr: TempStr = oStat.UndeliveredMessages
Dim I
Dim oMessage
If InStr(TempStr,Chr(13) & Chr(10)) Then
Dim TempArr: TempArr = Split(TempStr, Chr(13) & Chr(10))
QueueCount = UBound(TempArr)
Else
If Len(TempStr) > 0 Then QueueCount = 1
End If
WScript.Echo "Undelivered Messages: " & QueueCount
If QueueCount < WarnCount Then
Set oStat = Nothing
Set oApp = Nothing
WScript.Quit 0
Else
Set oMessage = CreateObject("hMailServer.Message")
oMessage.From = FromEmail
oMessage.AddRecipient ToName, ToEmail ' Recipient 1
'oMessage.AddRecipient "Manager", "someone@somedomain.tld" ' Recipient 2 etc
oMessage.Subject = "Warning - Queue count: " & QueueCount
oMessage.Body = "Mail server queue length above threshold! Queue count: " & QueueCount
'oMessage.HTMLBody = "Mail server queue length above threshold! Queue count: " & QueueCount
oMessage.Save
WScript.Echo "Alert email generated"
Set oStat = Nothing
Set oApp = Nothing
WScript.Quit 1
End If
Set oStat = Nothing
Set oApp = Nothing
Output = "ERROR!"
WScript.StdOut.Write OutPut
WScript.Quit 3
Or call this from a monitoring tool & check the return code. 0 is OK, 1 is warning, 3 is error.
Should be simple to use the oMessage stuff in this script to modify the other scripts or add the needed portions here if desired.
Bill
hMailServer build LIVE on my servers: 5.4-B2014050402
#hmailserver on FreeNode IRC https://webchat.freenode.net/?channels=#hmailserver
*** ABSENT FROM hMail! Those in IRC know how to find me if urgent. ***
#hmailserver on FreeNode IRC https://webchat.freenode.net/?channels=#hmailserver
*** ABSENT FROM hMail! Those in IRC know how to find me if urgent. ***
Re: Nagios, NRPE scripts.
Can't edit my post so guess I'll make a new one. 
As so graciously pointed out by smarty pants Mr DooM if your queue is clogged up with spam how do you expect to get this alert sent thru the same server?
Well:
- The alert messages are added to the 'immediate' queue vs future delivery (IOW: "As soon as possible") just like bounces & new emails.
- Perhaps not ideal but at least they will be delivered before messages queued in future (retries) and better late than never.
- Feel free to call it from a monitoring program & act based on the return code. (Such as send email to alternate server directly vs relaying thru overloaded one, etc)
- To minimize delivery delay use a local account & not forward or send to an outside one as those can be queued into future.
At some point I'll likely look into a way to specify 'front of queue' for oMessage's or someone could call BLAT or such to send via a different server if desired if they were ultra paranoid about delay in getting these. In meantime think this is better than nothing & it'd be interesting to hear feedback from people on their experience with getting these alerts with a busy/overloaded queue.
Bill
Ps. Btw thx DooM for pointing out the obvious which eluded me until you brought it to my attention & the light went on.

As so graciously pointed out by smarty pants Mr DooM if your queue is clogged up with spam how do you expect to get this alert sent thru the same server?

Well:
- The alert messages are added to the 'immediate' queue vs future delivery (IOW: "As soon as possible") just like bounces & new emails.
- Perhaps not ideal but at least they will be delivered before messages queued in future (retries) and better late than never.

- Feel free to call it from a monitoring program & act based on the return code. (Such as send email to alternate server directly vs relaying thru overloaded one, etc)
- To minimize delivery delay use a local account & not forward or send to an outside one as those can be queued into future.
At some point I'll likely look into a way to specify 'front of queue' for oMessage's or someone could call BLAT or such to send via a different server if desired if they were ultra paranoid about delay in getting these. In meantime think this is better than nothing & it'd be interesting to hear feedback from people on their experience with getting these alerts with a busy/overloaded queue.
Bill
Ps. Btw thx DooM for pointing out the obvious which eluded me until you brought it to my attention & the light went on.

hMailServer build LIVE on my servers: 5.4-B2014050402
#hmailserver on FreeNode IRC https://webchat.freenode.net/?channels=#hmailserver
*** ABSENT FROM hMail! Those in IRC know how to find me if urgent. ***
#hmailserver on FreeNode IRC https://webchat.freenode.net/?channels=#hmailserver
*** ABSENT FROM hMail! Those in IRC know how to find me if urgent. ***
Re: Nagios, NRPE scripts.
OK here is an updated version that also alerts on smtp/pop3/imap connection counts:
I put some more thought into DooM's concern about an overloaded queue & I'm thinking that if one runs this script frequently enough (it seems to use very little resources so every 10 or 5 minutes shouldn't be a problem) and the levels are set to a reasonable level then odds are the queue shouldn't have a chance to become TOO overloaded in that short amount of time for the alert to be delayed by too much to be useful. And if the SMTP & max recipients per message limits are set at a reasonable level seems only so many messages could possibly be queued in that amount of time.. YES if you ran this AFTER your queue already had 100k messages queued up odds are it won't be much use but hopefully it kicks in well before that.
Anyhow hopefully this proves useful to people.
Bill
Code: Select all
Option Explicit
On Error Resume Next
'This script sends email alert when queue above defined limit
'Original by rolaids0 - "Nagios, NRPE scripts."
'administrator information
Const AdminUser = "hmail_admin_username"
Const AdminPassword = "hmail_admin_password"
Const QueueWarnCount = 5
Const SMTPWarnCount = 5
Const POP3WarnCount = 5
Const IMAPWarnCount = 5
Const FromEmail = "server@yourdomain.tld"
Const ToName = "Admin"
Const ToEmail = "admin@somedomain.tld"
'don't edit below
Dim oApp: Set oApp = CreateObject("hMailServer.Application")
Call oApp.Authenticate(AdminUser,AdminPassword)
oApp.Connect
'catch connection errors
If Err.Number <> 0 Then
WScript.StdOut.Write "Error connecting!"
WScript.Quit 3
End If
Dim QueueCount: QueueCount = 0
Dim OutPut
Dim oStat: Set oStat = oApp.Status
Dim TempStr: TempStr = oStat.UndeliveredMessages
Dim SMTPConCount: SMTPConCount = oStat.SessionCount(1)
Dim POP3ConCount: POP3ConCount = oStat.SessionCount(3)
Dim IMAPConCount: IMAPConCount = oStat.SessionCount(5)
Dim I
Dim oMessage
If InStr(TempStr,Chr(13) & Chr(10)) Then
Dim TempArr: TempArr = Split(TempStr, Chr(13) & Chr(10))
QueueCount = UBound(TempArr)
Else
If Len(TempStr) > 0 Then QueueCount = 1
End If
WScript.Echo "Undelivered Messages: " & QueueCount
WScript.Echo "SMTP Connections: " & SMTPConCount
WScript.Echo "POP3 Connections: " & POP3ConCount
WScript.Echo "IMAP Connections: " & IMAPConCount
If QueueCount < QueueWarnCount And SMTPConCount < SMTPWarnCount And POP3ConCount < POP3WarnCount And IMAPConCount < IMAPWarnCount Then
Set oStat = Nothing
Set oApp = Nothing
WScript.Quit 0
Else
Set oMessage = CreateObject("hMailServer.Message")
oMessage.From = FromEmail
oMessage.AddRecipient ToName, ToEmail ' Recipient 1
'oMessage.AddRecipient "Manager", "someone@somedomain.tld" ' Recipient 2 etc
oMessage.Subject = "Warning - QUEUE: " & QueueCount & " SMTP: " & SMTPConCount & " POP3: " & POP3ConCount & " IMAP: " & IMAPConCount
oMessage.Body = "Mail server queue length or connection count(s) above threshold! QUEUE: " & QueueCount & " SMTP: " & SMTPConCount & " POP3: " & POP3ConCount & " IMAP: " & IMAPConCount
'oMessage.HTMLBody = "HTML VERSION COULD GO HERE - Plain text version should work fine"
oMessage.Save
WScript.Echo "Alert email generated"
Set oStat = Nothing
Set oApp = Nothing
WScript.Quit 1
End If
Set oStat = Nothing
Set oApp = Nothing
Output = "ERROR!"
WScript.StdOut.Write OutPut
WScript.Quit 3

Anyhow hopefully this proves useful to people.

Bill
hMailServer build LIVE on my servers: 5.4-B2014050402
#hmailserver on FreeNode IRC https://webchat.freenode.net/?channels=#hmailserver
*** ABSENT FROM hMail! Those in IRC know how to find me if urgent. ***
#hmailserver on FreeNode IRC https://webchat.freenode.net/?channels=#hmailserver
*** ABSENT FROM hMail! Those in IRC know how to find me if urgent. ***
Re: Nagios, NRPE scripts.
If an overloaded queue is a big issue, then someone could use some sort of mail sending app to directly send an email to a phone (email to txt).... A common list of services are:
http://www.emailtextmessages.com/
I do this with Nagios so if the SMTP service is down, it'll directly send a message to my phone as a txt.
http://www.emailtextmessages.com/
I do this with Nagios so if the SMTP service is down, it'll directly send a message to my phone as a txt.
Re: Nagios, NRPE scripts.
Updated script that also emails alerts for autobans or if # of IPRanges exceeds certain #:
Code: Select all
Option Explicit
On Error Resume Next
'This script sends email alert when queue above defined limit
'Original by rolaids0 - "Nagios, NRPE scripts."
'administrator information
Const AdminUser = "hmail_admin_username"
Const AdminPassword = "hmail_admin_password"
Const QueueWarnCount = 5
Const SMTPWarnCount = 5
Const POP3WarnCount = 5
Const IMAPWarnCount = 5
Const AutobanWarnCount = 1
Const RangesWarnCount = 40
Const FromEmail = "server@yourdomain.tld"
Const ToName = "Admin"
Const ToEmail = "admin@somedomain.tld"
'don't edit below
Dim oApp: Set oApp = CreateObject("hMailServer.Application")
Call oApp.Authenticate(AdminUser,AdminPassword)
oApp.Connect
'catch connection errors
If Err.Number <> 0 Then
WScript.StdOut.Write "Error connecting!"
WScript.Quit 3
End If
Dim QueueCount: QueueCount = 0
Dim OutPut
Dim oStat: Set oStat = oApp.Status
Dim TempStr: TempStr = oStat.UndeliveredMessages
Dim SMTPConCount: SMTPConCount = oStat.SessionCount(1)
Dim POP3ConCount: POP3ConCount = oStat.SessionCount(3)
Dim IMAPConCount: IMAPConCount = oStat.SessionCount(5)
Dim I
Dim RangeLoop
Dim oMessage
If InStr(TempStr,Chr(13) & Chr(10)) Then
Dim TempArr: TempArr = Split(TempStr, Chr(13) & Chr(10))
QueueCount = UBound(TempArr)
Else
If Len(TempStr) > 0 Then QueueCount = 1
End If
Dim oSecRanges: Set oSecRanges = oApp.Settings.SecurityRanges
Dim SecRangeCount: SecRangeCount = oSecRanges.Count
Dim oRange
Dim AutoBanCount: AutoBanCount = 0
For I = 0 to oSecRanges.Count - 1
Set oRange = oSecRanges.Item(I)
if oRange.Expires Then
AutoBanCount = AutoBanCount + 1
' WScript.StdOut.Write AutoBanCount
End If
Next
WScript.Echo "Undelivered Messages: " & QueueCount
WScript.Echo "SMTP Connections: " & SMTPConCount
WScript.Echo "POP3 Connections: " & POP3ConCount
WScript.Echo "IMAP Connections: " & IMAPConCount
WScript.Echo "IP Ranges Count: " & SecRangeCount
WScript.Echo "Autoban Count: " & AutoBanCount
If AutoBanCount < AutobanWarnCount And SecRangeCount < RangesWarnCount And QueueCount < QueueWarnCount And SMTPConCount < SMTPWarnCount And POP3ConCount < POP3WarnCount And IMAPConCount < IMAPWarnCount Then
Set oStat = Nothing
Set oApp = Nothing
WScript.Quit 0
Else
Set oMessage = CreateObject("hMailServer.Message")
oMessage.From = FromEmail
oMessage.AddRecipient ToName, ToEmail ' Recipient 1
'oMessage.AddRecipient "Manager", "someone@somedomain.tld" ' Recipient 2 etc
oMessage.Subject = "Warning - QUEUE: " & QueueCount & " SMTP: " & SMTPConCount & " POP3: " & POP3ConCount & " IMAP: " & IMAPConCount & " BANS: " & AutoBanCount
oMessage.Body = "Mail server queue length or connection count(s) above threshold! QUEUE: " & QueueCount & " SMTP: " & SMTPConCount & " POP3: " & POP3ConCount & " IMAP: " & IMAPConCount & " BANS: " & AutoBanCount
'oMessage.HTMLBody = "Mail server queue length above threshold! Queue count: " & QueueCount
oMessage.Save
WScript.Echo "Alert email generated"
Set oStat = Nothing
Set oApp = Nothing
WScript.Quit 1
End If
Set oStat = Nothing
Set oApp = Nothing
Output = "ERROR!"
WScript.StdOut.Write OutPut
WScript.Quit 3
- Attachments
-
- hmailalert10-12-2011.zip
- (1.23 KiB) Downloaded 478 times
hMailServer build LIVE on my servers: 5.4-B2014050402
#hmailserver on FreeNode IRC https://webchat.freenode.net/?channels=#hmailserver
*** ABSENT FROM hMail! Those in IRC know how to find me if urgent. ***
#hmailserver on FreeNode IRC https://webchat.freenode.net/?channels=#hmailserver
*** ABSENT FROM hMail! Those in IRC know how to find me if urgent. ***
Re: Nagios, NRPE scripts.
Updated version adds alert for user sending excessive # of messages. REQUIRES use of 5.4's Archiving feature to function (It works by looping thru the archive tree counting # of Sent EML files rather than counting as messages are sent.
If you don't use archiving or don't want/need message count alerts use the previous version above.
Note the new cont & vars added
If you don't use archiving or don't want/need message count alerts use the previous version above.
Note the new cont & vars added
Code: Select all
Option Explicit
On Error Resume Next
'This script sends email alert when queue, SMTP, POP or IMAP above defined limits
'Original by rolaids0 - "Nagios, NRPE scripts."
'administrator information
Const AdminUser = "hmail_admin_username"
Const AdminPassword = "hmail_admin_password"
Const QueueWarnCount = 90
Const SMTPWarnCount = 20
Const POP3WarnCount = 15
Const IMAPWarnCount = 10
Const AutobanWarnCount = 1
Const RangesWarnCount = 500
Const FromEmail = "server@yourdomain.tld"
Const ToName = "Admin"
Const ToEmail = "admin@somedomain.tld"
Const MaxSentWarnCount = 500
Const RootFolder = "C:\MailArchive"
'don't edit below
Dim oApp: Set oApp = CreateObject("hMailServer.Application")
Call oApp.Authenticate(AdminUser,AdminPassword)
oApp.Connect
'catch connection errors
If Err.Number <> 0 Then
WScript.StdOut.Write "Error connecting!"
WScript.Quit 3
End If
Dim QueueCount: QueueCount = 0
Dim OutPut
Dim oStat: Set oStat = oApp.Status
Dim TempStr: TempStr = oStat.UndeliveredMessages
Dim SMTPConCount: SMTPConCount = oStat.SessionCount(1)
Dim POP3ConCount: POP3ConCount = oStat.SessionCount(3)
Dim IMAPConCount: IMAPConCount = oStat.SessionCount(5)
Dim I
Dim RangeLoop
Dim oMessage
Dim PreviousDate 'holds the previous date (-1 day)
Dim FSO 'file system object
Dim ObjDomain 'FSO.Folder -- domain folder
Dim ObjFolder 'FSO.Folder -- user folders
Dim ObjFile 'FSO.File -- the email file
Dim ObjRootFolder 'FSO.Folder -- root folder
Dim MailCount
Dim DomainCount
Dim SentAlertCount
Dim MaxSentAlert
If InStr(TempStr,Chr(13) & Chr(10)) Then
Dim TempArr: TempArr = Split(TempStr, Chr(13) & Chr(10))
QueueCount = UBound(TempArr)
Else
If Len(TempStr) > 0 Then QueueCount = 1
End If
Dim oSecRanges: Set oSecRanges = oApp.Settings.SecurityRanges
Dim SecRangeCount: SecRangeCount = oSecRanges.Count
Dim oRange
Dim AutoBanCount: AutoBanCount = 0
For I = 0 to oSecRanges.Count - 1
Set oRange = oSecRanges.Item(I)
if oRange.Expires Then
AutoBanCount = AutoBanCount + 1
WScript.StdOut.Write AutoBanCount
End If
Next
Set FSO = CreateObject("Scripting.FileSystemObject")
Set ObjRootFolder = FSO.GetFolder(RootFolder)
DomainCount = 0
MaxSentAlert=""
SentAlertCount = 0
'loop through each of the sub folders (domains) in the archive folder looking for sub folders to those.
For Each ObjDomain in ObjRootFolder.SubFolders
If ObjDomain.Name <> "Inbound" and ObjDomain.Name <> "Error" Then
'now loop through each users's folder
For Each ObjFolder In ObjDomain.SubFolders
If DateValue(ObjFolder.DateLastModified) >= DateValue(Date-1) Then
DomainCount = DomainCount + 1
MailCount=0
'process each file
For Each ObjFile in ObjFolder.Files
If LCase(FSO.GetExtensionName(ObjFile.Name)) = "eml" Then
If DateValue(ObjFile.DateLastModified) >= DateValue(Date-1) Then
If InStr(ObjFile.Name,"Sent") Then MailCount=MailCount+1
End If
End If
WScript.Sleep 0
Next
if MailCount >= MaxSentWarnCount then
WScript.Echo MailCount & " " & ObjFolder.Name & "@" & ObjDomain.Name
MaxSentAlert = MaxSentAlert & ObjFolder.Name & "@" & ObjDomain.Name & "->" & MailCount & VbCrLf
SentAlertCount=SentAlertCount+MailCount
End If
End If
WScript.Sleep 1
Next
WScript.Sleep 0
End If
Next
' Comment out these if you only plan to run as scheduled task
WScript.Echo "Undelivered Messages: " & QueueCount
WScript.Echo "SMTP Connections: " & SMTPConCount
WScript.Echo "POP3 Connections: " & POP3ConCount
WScript.Echo "IMAP Connections: " & IMAPConCount
WScript.Echo "IP Ranges Count: " & SecRangeCount
WScript.Echo "Autoban Count: " & AutoBanCount
WScript.Echo "Changed Box Count: " & DomainCount
WScript.Echo "Sent Alert Count: " & SentAlertCount
If AutoBanCount < AutobanWarnCount And SecRangeCount < RangesWarnCount And QueueCount < QueueWarnCount And SMTPConCount < SMTPWarnCount And POP3ConCount < POP3WarnCount And IMAPConCount < IMAPWarnCount And MaxSentAlert = "" Then
Set oStat = Nothing
Set oApp = Nothing
WScript.Quit 0
Else
Set oMessage = CreateObject("hMailServer.Message")
oMessage.From = FromEmail
oMessage.AddRecipient ToName, ToEmail ' Recipient 1
'oMessage.AddRecipient "Manager", "someone@somedomain.tld" ' Recipient 2 etc
oMessage.Subject = "Warning - QUEUE: " & QueueCount & " SMTP: " & SMTPConCount & " POP3: " & POP3ConCount & " IMAP: " & IMAPConCount & " BANS: " & AutoBanCount & " SENT: " & SentAlertCount
oMessage.Body = "Mail server queue length or connection count(s) above threshold!" & VbCrLf & "QUEUE: " & QueueCount & " SMTP: " & SMTPConCount & " POP3: " & POP3ConCount & " IMAP: " & IMAPConCount & " BANS: " & AutoBanCount & " SENT: " & SentAlertCount & VbCrLf & MaxSentAlert
'oMessage.HTMLBody = "Mail server queue length above threshold! Queue count: " & QueueCount
oMessage.Save
WScript.Echo "Alert email generated"
Set oStat = Nothing
Set oApp = Nothing
WScript.Quit 1
End If
Set oStat = Nothing
Set oApp = Nothing
Output = "ERROR!"
WScript.StdOut.Write OutPut
WScript.Quit 3
hMailServer build LIVE on my servers: 5.4-B2014050402
#hmailserver on FreeNode IRC https://webchat.freenode.net/?channels=#hmailserver
*** ABSENT FROM hMail! Those in IRC know how to find me if urgent. ***
#hmailserver on FreeNode IRC https://webchat.freenode.net/?channels=#hmailserver
*** ABSENT FROM hMail! Those in IRC know how to find me if urgent. ***
Re: Nagios, NRPE scripts.
Great script. Maybe this should be a feature of the HMS by default.
Thank you
Br,
Dali
Thank you
Br,
Dali
Re: Nagios, NRPE scripts.
Hello Bill. First I would like to thank you for putting an effort in making and sharing this awesome script. I noticed a problem though
I have the script set to auto run every 5 minutes. In the past, there was a problem where it would hang on 'running' in the schueduler windows, I resolved this by ticking the feature to automatically stop the task if it is running for 10 minutes, because if everything is ok the task is done within few seconds. (EDIT) Before I did this, IIRC it would hang on "running" if 1 warning mail was generated already resulting in not sending subsequent mails unless the task is resetted.
The big issue i noticed is that when it is set to 5 minutes, as the time goes by it seems to "build up" IMAP connections and keeps open SMTP connection. I usually have 24-50 IMAP connections, however, when this thing happens it goes up to 150 IMAP connections and 1 SMTP connection is always open, generating the warning email because 100+ connections triggers the warning mail send. I have checked the logs at the time this happened, everything seems fine. Note that my server and most of the clients are on the same network so diferentiating the connections made by the server where hmail is installed and the clients is not possible because they share the same public IP. Other IPs that are accessing are valid and known, checked them. No auto IP-bans are generated. When i disabled the schuedule for the task, the IMAP connection count went down to normal level after about 3-5 mins, 1 constant SMTP connection was ended as well because the counter resetted to 0. It seems like the script is generating a new connection every time, while the previous connection is not being closed. I've tried to find the timeout for IMAP for hMail, seems to be 30 mins, meaning that if I have set task to run every 5 mins, it would generate 6 connections while 1 would end at that time, leading to a buildup of IMAP connections. This is the only theory i have to explain this behaviour.
Any ideas?
I have the script set to auto run every 5 minutes. In the past, there was a problem where it would hang on 'running' in the schueduler windows, I resolved this by ticking the feature to automatically stop the task if it is running for 10 minutes, because if everything is ok the task is done within few seconds. (EDIT) Before I did this, IIRC it would hang on "running" if 1 warning mail was generated already resulting in not sending subsequent mails unless the task is resetted.
The big issue i noticed is that when it is set to 5 minutes, as the time goes by it seems to "build up" IMAP connections and keeps open SMTP connection. I usually have 24-50 IMAP connections, however, when this thing happens it goes up to 150 IMAP connections and 1 SMTP connection is always open, generating the warning email because 100+ connections triggers the warning mail send. I have checked the logs at the time this happened, everything seems fine. Note that my server and most of the clients are on the same network so diferentiating the connections made by the server where hmail is installed and the clients is not possible because they share the same public IP. Other IPs that are accessing are valid and known, checked them. No auto IP-bans are generated. When i disabled the schuedule for the task, the IMAP connection count went down to normal level after about 3-5 mins, 1 constant SMTP connection was ended as well because the counter resetted to 0. It seems like the script is generating a new connection every time, while the previous connection is not being closed. I've tried to find the timeout for IMAP for hMail, seems to be 30 mins, meaning that if I have set task to run every 5 mins, it would generate 6 connections while 1 would end at that time, leading to a buildup of IMAP connections. This is the only theory i have to explain this behaviour.
Any ideas?
Re: Nagios, NRPE scripts.
Bill48105 wrote:Updated script that also emails alerts for autobans or if # of IPRanges exceeds certain #:Code: Select all
Option Explicit On Error Resume Next 'This script sends email alert when queue above defined limit 'Original by rolaids0 - "Nagios, NRPE scripts." 'administrator information Const AdminUser = "hmail_admin_username" Const AdminPassword = "hmail_admin_password" Const QueueWarnCount = 5 Const SMTPWarnCount = 5 Const POP3WarnCount = 5 Const IMAPWarnCount = 5 Const AutobanWarnCount = 1 Const RangesWarnCount = 40 Const FromEmail = "server@yourdomain.tld" Const ToName = "Admin" Const ToEmail = "admin@somedomain.tld" 'don't edit below Dim oApp: Set oApp = CreateObject("hMailServer.Application") Call oApp.Authenticate(AdminUser,AdminPassword) oApp.Connect 'catch connection errors If Err.Number <> 0 Then WScript.StdOut.Write "Error connecting!" WScript.Quit 3 End If Dim QueueCount: QueueCount = 0 Dim OutPut Dim oStat: Set oStat = oApp.Status Dim TempStr: TempStr = oStat.UndeliveredMessages Dim SMTPConCount: SMTPConCount = oStat.SessionCount(1) Dim POP3ConCount: POP3ConCount = oStat.SessionCount(3) Dim IMAPConCount: IMAPConCount = oStat.SessionCount(5) Dim I Dim RangeLoop Dim oMessage If InStr(TempStr,Chr(13) & Chr(10)) Then Dim TempArr: TempArr = Split(TempStr, Chr(13) & Chr(10)) QueueCount = UBound(TempArr) Else If Len(TempStr) > 0 Then QueueCount = 1 End If Dim oSecRanges: Set oSecRanges = oApp.Settings.SecurityRanges Dim SecRangeCount: SecRangeCount = oSecRanges.Count Dim oRange Dim AutoBanCount: AutoBanCount = 0 For I = 0 to oSecRanges.Count - 1 Set oRange = oSecRanges.Item(I) if oRange.Expires Then AutoBanCount = AutoBanCount + 1 ' WScript.StdOut.Write AutoBanCount End If Next WScript.Echo "Undelivered Messages: " & QueueCount WScript.Echo "SMTP Connections: " & SMTPConCount WScript.Echo "POP3 Connections: " & POP3ConCount WScript.Echo "IMAP Connections: " & IMAPConCount WScript.Echo "IP Ranges Count: " & SecRangeCount WScript.Echo "Autoban Count: " & AutoBanCount If AutoBanCount < AutobanWarnCount And SecRangeCount < RangesWarnCount And QueueCount < QueueWarnCount And SMTPConCount < SMTPWarnCount And POP3ConCount < POP3WarnCount And IMAPConCount < IMAPWarnCount Then Set oStat = Nothing Set oApp = Nothing WScript.Quit 0 Else Set oMessage = CreateObject("hMailServer.Message") oMessage.From = FromEmail oMessage.AddRecipient ToName, ToEmail ' Recipient 1 'oMessage.AddRecipient "Manager", "someone@somedomain.tld" ' Recipient 2 etc oMessage.Subject = "Warning - QUEUE: " & QueueCount & " SMTP: " & SMTPConCount & " POP3: " & POP3ConCount & " IMAP: " & IMAPConCount & " BANS: " & AutoBanCount oMessage.Body = "Mail server queue length or connection count(s) above threshold! QUEUE: " & QueueCount & " SMTP: " & SMTPConCount & " POP3: " & POP3ConCount & " IMAP: " & IMAPConCount & " BANS: " & AutoBanCount 'oMessage.HTMLBody = "Mail server queue length above threshold! Queue count: " & QueueCount oMessage.Save WScript.Echo "Alert email generated" Set oStat = Nothing Set oApp = Nothing WScript.Quit 1 End If Set oStat = Nothing Set oApp = Nothing Output = "ERROR!" WScript.StdOut.Write OutPut WScript.Quit 3
I tried running the script from cmd prompt for testing.. The only thing it is displaying is autoban.. even though there is nothing in autoban.. everything else is blank.. it does email me though..
i'm on 5.4 not working right.. looking for another script.. not sure if anyone has anything updated that may work..
Re: Nagios, NRPE scripts.
What exactly are you hoping to see?
Please post the diagnostics for your domain...rob2k2 wrote:i'm on 5.4 not working right..
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation
https://www.hmailserver.com/documentation
Re: Nagios, NRPE scripts.
Does this script still work ?
How do I use it in HmailServer ?
How do I use it in HmailServer ?
Re: Nagios, NRPE scripts.
rolaids0 wrote:Yes, No, Maybe. Nagios does a lot.... This script was designed to be used with NRPE (Nagios Remote Plug-In Executor.)
http://www.nagios.org
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation
https://www.hmailserver.com/documentation