Nagios, NRPE scripts.

This section contains scripts that hMailServer has contributed with. hMailServer 5 is needed to use these.
Post Reply
rolaids0
Normal user
Normal user
Posts: 150
Joined: 2010-04-27 02:03
Location: Florida
Contact:

Nagios, NRPE scripts.

Post by rolaids0 » 2011-02-23 00:32

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 878 times

Bill48105
Developer
Developer
Posts: 6189
Joined: 2010-04-24 23:16
Location: Michigan, USA

Re: Nagios, NRPE scripts.

Post by Bill48105 » 2011-02-24 01:00

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
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. ***

User avatar
ditoh1
New user
New user
Posts: 7
Joined: 2011-06-09 21:09
Location: Washington DC

Re: Nagios, NRPE scripts.

Post by ditoh1 » 2011-06-23 19:53

Now, I'm guessing here, Nagios would recieve this information via System Log file / SNMP, am I right?
Thanks!!!

-D

rolaids0
Normal user
Normal user
Posts: 150
Joined: 2010-04-27 02:03
Location: Florida
Contact:

Re: Nagios, NRPE scripts.

Post by rolaids0 » 2011-06-23 19:55

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

User avatar
ditoh1
New user
New user
Posts: 7
Joined: 2011-06-09 21:09
Location: Washington DC

Re: Nagios, NRPE scripts.

Post by ditoh1 » 2011-06-23 19:56

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
Thanks!!!

-D

rolaids0
Normal user
Normal user
Posts: 150
Joined: 2010-04-27 02:03
Location: Florida
Contact:

Re: Nagios, NRPE scripts.

Post by rolaids0 » 2011-06-23 20:43

These scripts won't directly work over SNMP.

Bill48105
Developer
Developer
Posts: 6189
Joined: 2010-04-24 23:16
Location: Michigan, USA

Re: Nagios, NRPE scripts.

Post by Bill48105 » 2011-06-23 21:09

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
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. ***

Bill48105
Developer
Developer
Posts: 6189
Joined: 2010-04-24 23:16
Location: Michigan, USA

Re: Nagios, NRPE scripts.

Post by Bill48105 » 2011-06-23 22:15

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:

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
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
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. ***

Bill48105
Developer
Developer
Posts: 6189
Joined: 2010-04-24 23:16
Location: Michigan, USA

Re: Nagios, NRPE scripts.

Post by Bill48105 » 2011-06-23 23:27

Can't edit my post so guess I'll make a new one. :D

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? :D

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. :D
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. ***

Bill48105
Developer
Developer
Posts: 6189
Joined: 2010-04-24 23:16
Location: Michigan, USA

Re: Nagios, NRPE scripts.

Post by Bill48105 » 2011-06-24 01:55

OK here is an updated version that also alerts on smtp/pop3/imap connection counts:

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
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.:D

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. ***

rolaids0
Normal user
Normal user
Posts: 150
Joined: 2010-04-27 02:03
Location: Florida
Contact:

Re: Nagios, NRPE scripts.

Post by rolaids0 » 2011-06-25 17:35

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.

Bill48105
Developer
Developer
Posts: 6189
Joined: 2010-04-24 23:16
Location: Michigan, USA

Re: Nagios, NRPE scripts.

Post by Bill48105 » 2011-10-12 16:43

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 280 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. ***

Bill48105
Developer
Developer
Posts: 6189
Joined: 2010-04-24 23:16
Location: Michigan, USA

Re: Nagios, NRPE scripts.

Post by Bill48105 » 2013-01-17 09:10

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

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. ***

kdiamond
Normal user
Normal user
Posts: 86
Joined: 2013-03-20 10:51

Re: Nagios, NRPE scripts.

Post by kdiamond » 2014-07-09 00:13

Great script. Maybe this should be a feature of the HMS by default.

Thank you
Br,
Dali

pedja.m
New user
New user
Posts: 2
Joined: 2014-03-21 16:38

Re: Nagios, NRPE scripts.

Post by pedja.m » 2014-09-17 14:54

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?

rob2k2
New user
New user
Posts: 28
Joined: 2013-12-12 03:07

Re: Nagios, NRPE scripts.

Post by rob2k2 » 2016-03-09 05:23

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..

User avatar
mattg
Moderator
Moderator
Posts: 19979
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Nagios, NRPE scripts.

Post by mattg » 2016-03-09 07:14

What exactly are you hoping to see?
rob2k2 wrote:i'm on 5.4 not working right..
Please post the diagnostics for your domain...
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

djhabana
Normal user
Normal user
Posts: 72
Joined: 2013-12-14 09:19

Re: Nagios, NRPE scripts.

Post by djhabana » 2017-11-01 09:00

Does this script still work ?
How do I use it in HmailServer ?

User avatar
mattg
Moderator
Moderator
Posts: 19979
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Nagios, NRPE scripts.

Post by mattg » 2017-11-01 09:42

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

Post Reply