Quantcast
Channel: VBForums - ASP, VB Script
Viewing all articles
Browse latest Browse all 687

extracting autoban ip's from hmailserver to text file ? visual basic script included

$
0
0
Hey,

I have this visual basic script. I run it on server 2008 and it works with hmailserver . Basically the script sends an email to an account using the mailserver and informs me about how many undelivered messages, smtp connections,pop3 connections, imap connections, ip ranges count, and autoban count and than generates an automated email and sends it to the email address in the script . I want it to take the autoban information which is an ip addresses but the information is listed in 5 columns ( name, lower ip, upper ip, priority, expires / expiry ) . it has one line per entry . This link contains a screenshot

http://www.google.ca/imgres?num=10&u...9,r:8,s:0,i:91 .

Here is the visual basic script

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 = "*****"
Const AdminPassword = "******"
Const QueueWarnCount = 5
Const SMTPWarnCount = 5
Const POP3WarnCount = 5
Const IMAPWarnCount = 5
Const AutobanWarnCount = 1
Const RangesWarnCount = 40
Const FromEmail = "*****@*****.*****.***"
Const ToName = "****"
Const ToEmail = "****@***.*****.***"


'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

does anyone know what code i need to edit? if there are certain statements i need to put in the code? any syntax tips? or maybe just point me in a different direction? I'm a complete noob when It comes to programming, and the reason I started getting into programming / scripting is because of windows server administration work .

thank you very much, :wave:

Viewing all articles
Browse latest Browse all 687

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>