KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

Check Domain and send alerts

 
Post new topic   Reply to topic    KiXforms Forum Index -> Script Archive
View previous topic :: View next topic  
Author Message
kholm
KiXforms Novice
KiXforms Novice


Joined: 22 May 2003
Posts: 4

PostPosted: Thu May 22, 2003 1:44 am    Post subject: Check Domain and send alerts Reply with quote

Domain Checker

This scrips checks/pings servers/routers/subnet and sends alerts via NetSend or/and EMail.
It is designed to run always on an exstra workstation in the domain.

It also checks available diskspace and eventlogs for errors/warnings on selected servers.

The funny part is the use of KiXforms - Resizeable and using icons to display status Wink
The usefull part is recieving mails/alerts nearly as soon as a problem arises on the network

The script uses DynoCOM to wrap Ping and to send EMails.
DynoCOM - Direct download
DynoCOM - Homepage

I hope the remarks in the ini-file samples in this post explaines the use of DomCheck.kix

DomCheck.kix
Code:

; KIXTART  4.20      - http://kixtart.org/downloads.html
; KIXFORMS 2.30 BETA - http://kixforms.org/assets/index.htm
; DynoCOM            - http://www.dynu.com/downloads.asp?id=16 / http://www.dynu.com/dynuping.asp

Break On

; Languagesetting for alertmessages
; English
$TSep = ','
$msgGtThan = " replytime greater than "
$msgAnsAgain = " answering agin"
$msgOkRap = 'OK-report from netchecker'
$msgError = "ERROR  "
$msgNoReply = " dosn't answer"
$msgErrRap = 'Error-Report from netchecker'
$msgErrLog = 'Error-Report from: '
$msgLogToBig = 'Alertfile to big'
$msgLogSize = 'The errorlog is greater than 20,000 Bytes'
$msgLogCheck = 'Please check the eventlog manually !!!'

; Danish
;$TSep = '.'
;$msgGtThan = " svartid større end "
;$msgAnsAgain = " svarer igen"
;$msgOkRap = 'OK-rapport fra netchecker'
;$msgError = "FEJL  "
;$msgNoReply = " svarer ikke"
;$msgErrRap = 'Fejlrapport fra netchecker'
;$msgErrLog = 'Fejlrapport fra: '
;$msgLogToBig = 'Alarmfil for stor'
;$msgLogSize = 'Fejlloggen er større end 20.000 Bytes'
;$msgLogCheck = 'Check venligst eventloggen manuelt !!!'
; END - Languagesetting for alertmessages

$RegKey = "HKCU\Software\KiXDomainChecker"
$StatRegKey = "HKLM\Software\KiXDomainChecker"

Global $AlertMsg
Global $SepLin
Global $MailSubject
Global $LF
Global $IniFile
Global $TimeOutLog
Global $CheckCount
Global $CheckCountLog
Global $SleepTime
Global $SleepTimeLog
Global $CheckLogs
Global $TimeOut
Global $Retry
Global $Fast
Global $MailServer
Global $MailServerName
Global $MailSender
Global $MailSenderName

$SepLin = '* * * * * * * * * * * *'

;//////////////
; Main form ...
;//////////////
$Form = CreateObject("Kixtart.Form")
$Form.Icon = 5
$Form.Text = "Domain checker"
$Form.BorderStyle = 2 ; Sizable
$Form.ClientWidth = ReadValueEx($RegKey,"ClientWidth",600)
$Form.ClientHeight = ReadValueEx($RegKey,"ClientHeight",400)
$Form.Left = ReadValueEx($RegKey,"Left",100)
$Form.Top = ReadValueEx($RegKey,"Top",100)
$Form.ClipChildren = 1

$btnRestart = $Form.Controls.ToolButton()
$btnRestart.Location = 5,5
$btnRestart.Size = 23,23
$btnRestart.Icon = 55
$btnRestart.FlatStyle = 1
$btnRestart.OnClick = "OnRestartClick"
$btnRestart.ToolTip = "Restart"

$btnCheckNow = $Form.Controls.ToolButton()
$btnCheckNow.Location = $btnRestart.Right,$btnRestart.Top
$btnCheckNow.Size = 23,23
$btnCheckNow.Icon = 10
$btnCheckNow.FlatStyle = 1
$btnCheckNow.OnClick = "DoCheck"
$btnCheckNow.ToolTip = "Check now"

$btnExit = $Form.Controls.ToolButton()
$btnExit.Location = $btnCheckNow.Right,$btnCheckNow.Top
$btnExit.Size = $btnCheckNow.Size
$btnExit.Icon = 9
$btnExit.FlatStyle = $btnCheckNow.FlatStyle
$btnExit.OnClick = "OnExitClick"
$btnExit.ToolTip = "Exit"

$lblSep = $Form.Label
$lblSep.Location = 2,$btnExit.Bottom + 5
$lblSep.BorderStyle = 5
$lblSep.Size = $Form.ClientWidth-5,2
$lblSep.Anchor = 7

$StatusMsg = $Form.Label
$StatusMsg.Location = 10,$lblSep.Bottom + 5
$StatusMsg.FontSize = $Form.FontSize + 4
$StatusMsg.Height = $StatusMsg.FontSize + 8
$StatusMsg.Width = 500
$StatusMsg.ForeColor = 255

$Timer = $Form.Timer(999)
$Timer.OnTimer = 'TimerCheck'

$lstView = $Form.ListView()
$lstView.Location = 0,$StatusMsg.Bottom + 5
$lstView.Right = $Form.ClientWidth
$lstView.Bottom = $Form.ClientHeight
$lstView.Anchor = 15
$lstView.SmallImageList = $Form.ImageList
$lstView.SmallImageList.Images.Add($Form.SmallImageList.Images(34)) ;Green
$lstView.SmallImageList.Images.Add($Form.SmallImageList.Images(53)) ;Yellow
$lstView.SmallImageList.Images.Add($Form.SmallImageList.Images(33)) ;Red
$lstView.SmallImageList.Images.Add($Form.SmallImageList.Images(7)) ;Logfile
$lstView.Sorted = 0
$lstView.View = 3
$RC = $lstView.Columns.Add("Ressource")
$RC = $lstView.Columns.Add("Type")
$RC = $lstView.Columns.Add("Last alert")
$RC = $lstView.Columns.Add("Status")
$RC = $lstView.Columns.Add("IP/Name")

;///////////////
; Initialize ...
;///////////////
FormInitiate()

;///////////////
; Run
;///////////////
While $form.Visible
   $RC = Execute($Form.DoEvents)
Loop

SaveSettings()

Exit 1


Function FormInitiate()
   $CheckLogs = 0
   $CheckCountLog = 0
   Initiate()
   $Form.Show
   DoCheck()
EndFunction


Function OnRestartClick()
   $Form.Hide
   $lstView.Items.Clear
   Initiate()
   $Form.Show
   DoCheck()
EndFunction


Function Initiate()
   Dim $WaitFrm
   $WaitFrm = CreateObject("Kixtart.Form")
   $WaitFrm.Caption = " One moment please..."
   $WaitFrm.ScaleWidth = 500
   $WaitFrm.ScaleHeight = 100
   $WaitFrm.FontSize = 12
   $WaitFrm.SysMenu = 0
   $WaitFrm.MousePointer = 11
   $WaitFrm.PrintXY(30,30,"Initiating domain check, one moment please......")
   $WaitFrm.Center

   $WaitFrm.Show

   $LF = Chr(10)
   $IniFile = @CurDir + "\DomCheck.ini"
   $TimeOutLog = @CurDir + "\TimeOut.log"

   $SleepTime = Val(ReadProfileString($IniFile,"Global","SleepTime"))
   $SleepTimeLog = Val(ReadProfileString($IniFile,"Global","SleepTimeLog"))
   $TimeOut = ReadProfileString($IniFile,"Global","TimeOut")
   $Retry = ReadProfileString($IniFile,"Global","Retry")
   $Fast = Val(ReadProfileString($IniFile,"Global","Fast"))
   $MailServer = ReadProfileString($IniFile,"Mail","MailServer")
   $Pos = InStr($MailServer,'.')
   $MailServerName = Left($MailServer,$Pos - 1)
   $MailSender = 'DomainChecker@@' + SubStr($MailServer,$Pos + 1)
   $MailSenderName = 'KiX Domain Checker'

   $HostStr = '' + ReadProfileString($IniFile,"Hosts","")
   If InStr($HostStr,$LF)
      $Hosts = Split(SubStr($HostStr,1,Len($HostStr) - 1),$LF)
      For Each $Host In $Hosts
         $IpAdr = ReadProfileString($IniFile,"Hosts",$Host)
         $Time = GetReply($IpAdr,$Host)
         Select
            Case $Time = 0
               $v = 2
            Case $Time < $Fast
               $v = 0
            Case 1
               $v = 1
         EndSelect
         $Item = $lstView.Items.Add($Host,$v)
         $Item.SubItems(1).Text = 'Net check'
         $Item.SubItems(2).Text = '          No alerts           '
         $Item.SubItems(3).Text = 'Ok'
         $Item.SubItems(4).Text = $IpAdr
      Next
   EndIf

   $EventLogStr = '' + ReadProfileString($IniFile,"Servers","")
   If InStr($EventLogStr,$LF)
      $EventLogs = Split(SubStr($EventLogStr,1,Len($EventLogStr) - 1),$LF)
      For Each $EventLog In $EventLogs
         $Item = $lstView.Items.Add($EventLog,3)
         $Item.SubItems(1).Text = 'Server check'
         $Item.SubItems(2).Text = '          No alerts           '
         $Item.SubItems(3).Text = 'Not checked'
         $Item.SubItems(4).Text = $EventLog
         $Num = $Num + 1
      Next
   EndIf

   ;Fit columns to form
   For Each $Column In $lstView.Columns
      $Column.Width = -1
      $Column.Width = -2
   Next
   ;Expand one column to ensure resize icon is shown in lower right corner
   $lstView.Columns(3).Width = $lstView.Columns(3).Width + 50
   
   $WaitFrm.Hide
EndFunction


Function OnExitClick()
   $Form.Hide
EndFunction


Function SaveSettings()
   $RC = WriteValue($RegKey,"ClientWidth",$Form.ClientWidth,"REG_DWORD")
   $RC = WriteValue($RegKey,"ClientHeight",$Form.ClientHeight,"REG_DWORD")
   $RC = WriteValue($RegKey,"Left",$Form.Left,"REG_DWORD")
   $RC = WriteValue($RegKey,"Top",$Form.Top,"REG_DWORD")
EndFunction


Function ReadValueEx($Key, $Value, $Default)
   Dim $Data
   $Data = ReadValue($Key,$Value)
   If @Error
      $ReadValueEx = $Default
   Else
      $ReadValueEx = $Data
   EndIf
EndFunction


Function TimerCheck()
   If $CheckCount >= $SleepTime Or $CheckCountLog >= $SleepTimeLog
      If $CheckCountLog >= $SleepTimeLog
         $CheckLogs = 1
      EndIf
      DoCheck()
   Else
      $TL = $SleepTime - $CheckCount
      $TLL = $SleepTimeLog - $CheckCountLog
      If $TLL < $TL
         $TL = $TLL
      EndIf
      $StatusMsg.Text = 'Seconds til next check: ' + $TL
      $CheckCount = $CheckCount + 1
      $CheckCountLog = $CheckCountLog + 1
   EndIf
EndFunction


Function DoCheck()
   $Start = @Ticks
   $Timer.OnTimer = ''
   $Form.MousePointer = 11
   $btnRestart.Enabled = 0
   $btnCheckNow.Enabled = 0
   $btnExit.Enabled = 0
   $lstView.Locked = 1
   For $Num = 0 To $lstView.Items.Count - 1
      $lstView.SetFocus
      $lstView.ListIndex = $Num
      If $lstView.FocusedItem.SubItems(1).Text = 'Net check'
         NetCheck($lstView.FocusedItem.SubItems(0).Text,$lstView.FocusedItem.SubItems(3).Text,$lstView.FocusedItem.SubItems(4).Text)
      Else
         If $CheckLogs
            CheckLog($lstView.FocusedItem.SubItems(0).Text)
         Else
            ChkDiskSpace($lstView.FocusedItem.SubItems(0).Text)
         EndIf
      EndIf
   Next
   $lstView.Locked = 0
   $btnRestart.Enabled = 1
   $btnCheckNow.Enabled = 1
   $btnExit.Enabled = 1
   $Form.MousePointer = 0
   $CheckCount = 0
   If $CheckLogs
      $CheckLogs = 0
      $CheckCountLog = 0
   Else
      $CheckCountLog = ((@Ticks - $Start) / 1000) + $CheckCountLog
   EndIf
   $Timer.OnTimer = 'TimerCheck'
EndFunction


Function NetCheck($Host,$PrevStat,$IpAdr)
   $StatusMsg.Text = 'Checking: ' + $Host
   $Time = GetReply($IpAdr,$Host)
   If $Time
      Select
         Case $Time < $Fast
            $v = 0
         Case 1
            $v = 1
      EndSelect
      $lstView.FocusedItem.SubItems(0).ImageIndex = $v
      $lstView.FocusedItem.SubItems(3).Text = '' + $Time + "ms"
      If $PrevStat = "Timeout"
         $AlertMsg = "OK " + $Host + $msgAnsAgain
         $MailSubject = $msgOkRap
         SendAlerts("NetAlerts","MailAdr",1,$Host)
      EndIf
   Else
      $lstView.FocusedItem.SubItems(0).ImageIndex = 2
      If $PrevStat <> "Timeout"
         $AlertMsg = $msgError + $Host + $msgNoReply
         $MailSubject = $msgErrRap
         SendAlerts("NetAlerts","MailAdr",1,$Host)
         $lstView.FocusedItem.SubItems(3).Text = "Timeout"
      EndIf
   EndIf
EndFunction


Function GetReply($ChkAdr,$Host)
   $GetReply = PingTime($ChkAdr,$TimeOut)
   If Not $GetReply
      $GetReply = PingTime($ChkAdr,$Retry)
      If $GetReply
         $AlertMsg = $Host + $msgGtThan + $TimeOut + "ms"
         WriteTimeOutLog()
      EndIf
   EndIf
EndFunction


Function PingTime($ChkAdr,$TimeOut)
   Dim $oPing,$Lines,$Line,$i
   $i = 0
   $oPing = CreateObject("Dynu.Ping")
   $Lines = Split($oPing.ping($ChkAdr, 1, 32, $TimeOut),@CRLF)
   Do
      $Line = $Lines[$i]
      $i = $i + 1
   Until InStr($Line,'TTL=') Or $i > UBound($Lines)
   If InStr($Line,'TTL=')
      Select
         Case InStr($Line,'<10')
            $PingTime = 9
         Case InStr($Line,'<1')
            $PingTime = 1
         Case 1
            $PingTime = Val(Split($Line,'=')[2])
      EndSelect
   Else
      $PingTime = 0
   EndIf
EndFunction


Function SendAlerts($Net,$Mail,Optional $Ping,Optional $Host)
   $StatusMsg.Text = 'Sending alert'
   $lstView.FocusedItem.SubItems(2).Text = @Date + ' ' + @Time
   SendNetAlert($Net)
   If $Ping
      WriteTimeOutLog()
      If $Host = $MailServerName ; Dont send Mail if it is the mailserver that isn't responding
         Return
      EndIf
   EndIf
   SendMail($Mail)
EndFunction


Function SendMail($MailAdr)
   Dim $oEmail,$MailAdr
   $MailStr = ReadProfileString($IniFile,$MailAdr,"")
   If InStr($MailStr,$LF) ; At least 1 recipient
      $oEmail = CreateObject("Dynu.Email")
      $oEmail.Host = $MailServer
      $oEmail.From = $MailSender
      $oEmail.FromName = $MailSenderName
      $MailStr = SubStr($MailStr,1,Len($MailStr) - 1)
      $MailList = Split($MailStr,$LF)
      For Each $MailAdr In $MailList
         $oEmail.AddAddress($MailAdr)
      Next
      $oEmail.Subject = $MailSubject
      $oEmail.Body = $AlertMsg
      $RC = $oEmail.Send()
      $oEmail = 0
   EndIf
EndFunction


Function SendNetAlert($AlertList)
   Dim $WksList,$Wksta
   $WksList = ReadProfileString($IniFile,$AlertList,"")
   If InStr($WksList,$LF)
      $WksList = Split($WksList,$LF)
      For $i = 0 To UBound($WksList) - 1
         $WkSta = $WksList[$i]
         If PingTime($WkSta,50) ; Wksta is Online, has answered within 50 ms
            $RC = SendMessage($WkSta,"$AlertMsg")
         EndIf
      Next
   EndIf
EndFunction


Function WriteTimeOutLog()
   If GetFileSize("$TimeOutLog") > 65000
      Copy "$TimeOutLog" "@CurDir\TimeOut.old"
      Del "$TimeOutLog"
   EndIf
   $RC = RedirectOutput("$TimeOutLog")
   @Date + Chr(9) + @Time + Chr(9) + $AlertMsg + @CRLF
   $RC = RedirectOutput("")
EndFunction


Function ChkDiskSpace($Server)
   $StatusMsg.Text = 'Checking available diskspace on: ' + $Server
   $AlertMsg = ''
   $DrvIni = @CurDir + '\' + $Server + '.ini'
   $DrvStr = ReadProfileString($DrvIni,'Drives','')
   If $DrvStr
      $lstView.FocusedItem.SubItems(3).Text = "Checking disks"
      $DLetters = Split($DrvStr,Chr(10))
      For $i = 0 To UBound($DLetters) - 1
         $DLetter = $DLetters[$i]
         $CritSize = Join(Split(Join(Split(ReadProfileString($DrvIni,'Drives','$DLetter'),'.'),''),','),'')
         $AlertSent = ReadValue($StatRegKey + '\' + $Server + '\Disks\' + $DLetter,'AlertSent')
         $NowSize = GetDiskSpace('\\' + $Server + '\' + $DLetter + '$$')
         If @Error
            $lstView.FocusedItem.SubItems(3).Text = "Disks Not checked"
            Return
         EndIf
         If $NowSize < $CritSize
            If $AlertSent <> 'Yes'
               $RC = WriteValue($StatRegKey + '\' + $Server + '\Disks\' + $DLetter,'AlertSent','Yes','REG_SZ')
               If $AlertMsg
                  $AlertMsg = $AlertMsg + @CRLF + @CRLF
               EndIf
               $AlertMsg = $AlertMsg + 'Server: ' + $Server + @CRLF
               $AlertMsg = $AlertMsg + 'Available diskspace on drive ' + $DLetter + ': is les than warningvalue (' + FormatNum($CritSize) + ' kb)' + @CRLF
               $AlertMsg = $AlertMsg + 'Available diskspace on drive ' + $DLetter + ': ' + FormatNum($NowSize) + ' kb' + @CRLF
               $AlertMsg = $AlertMsg + $SepLin + @CRLF
            EndIf
         Else
            If $AlertSent = 'Yes'
               $RC = WriteValue($StatRegKey + '\' + $Server + '\Disks\' + $DLetter,'AlertSent','No','REG_SZ')
            EndIf
         EndIf
      Next
      $lstView.FocusedItem.SubItems(3).Text = "Disks checked"
   Else
      $lstView.FocusedItem.SubItems(3).Text = "Disks Not checked"
   EndIf
   If $AlertMsg
      $MailSubject = $msgErrLog + $Server
      SendAlerts("LogAlerts","LogMailAdr")
   EndIf
EndFunction


Function FormatNum($Num)
   Dim $i, $p
   $NumStr = '' + $Num
   For $i = Len($NumStr) To 1 Step -1
      If $p > 0 And $p Mod 3 = 0
         $FormatNum = $TSep + $FormatNum
      EndIf
      $FormatNum = SubStr($NumStr,$i,1) + $FormatNum
      $p = 1 + $p
   Next
EndFunction


Function CheckLog($Server)
   $AlertMsg = ''
   CheckServerLog($Server)
   If $AlertMsg
      If Len($AlertMsg) > 20000
         $StartMsg = $msgLogToBig +  @CRLF + @CRLF
         $StartMsg = $StartMsg + $msgLogSize +  @CRLF
         $StartMsg = $StartMsg + $msgLogCheck +  @CRLF
         $StartMsg = $StartMsg + '* * * * * * * * * * * *' +  @CRLF + @CRLF
         $AlertMsg = $StartMsg + $AlertMsg
      EndIf
      $MailSubject = $msgErrLog + $Server
      SendAlerts("LogAlerts","LogMailAdr")
   EndIf
EndFunction


Function CheckServerLog($Server)
   Dim $OmitArray

   $ServerIni = @CurDir + '\' + $Server + '.ini'
   $AlertMsg = ''

   $ChkDate = Join(Split(@Date,'/'),'')

   $Logs = '' + ReadProfileString($ServerIni,'CheckLogs','Logs')
   If $Logs
      $StatusMsg.Text = 'Checking eventlog on: ' + $Server
      $lstView.FocusedItem.SubItems(3).Text = "Checking Eventlog"
      $Logs = Split(ReadProfileString($ServerIni,'CheckLogs','Logs'),',')
      For Each $Log In $Logs
         If $Log
            $LastDate = Right($ChkDate + ReadValue($StatRegKey + '\' + $Server + '\Logs\' + $Log,'Date'),8)
            If $LastDate < $ChkDate
               $ChkTime = '000000'
            Else
               $ChkTime = Right('000000' + ReadValue($StatRegKey + '\' + $Server + '\Logs\' + $Log,'Time'),6)
            EndIf
            $OmitList = '' + ReadProfileString($ServerIni,$Log,'')
            If $OmitList
               $OmitArray = Split($OmitList,Chr(10))
               ReDim Preserve $OmitArray[UBound($OmitArray) - 1]
            EndIf
            $ChkDT = $ChkDate + $ChkTime
            $EventTypes = Split('1 2') ; 1 = errors 2 = warning
            $NewDT = CheckEventLog($Server,$Log,$ChkDT,$EventTypes,$OmitArray)
            If @Error
               $lstView.FocusedItem.SubItems(3).Text = "Eventlog not checked"
               Return
            EndIf
            If $NewDT <> $ChkDT
               $RC = WriteValue($StatRegKey + '\' + $Server + '\Logs\' + $Log,'Date',Left($NewDT,8),'REG_SZ')
               $RC = WriteValue($StatRegKey + '\' + $Server + '\Logs\' + $Log,'Time',Right($NewDT,6),'REG_SZ')
            EndIf
            If Len($AlertMsg) > 20000
               Return
            EndIf
         EndIf
      Next
      $lstView.FocusedItem.SubItems(3).Text = "Eventlog checked"
   Else
      $lstView.FocusedItem.SubItems(3).Text = "Eventlog not checked"
   EndIf
EndFunction


Function CheckEventLog($Server,$Log,$DateTime,$Type,Optional $OmitSource)
   Dim $oEventLog,$Events,$EventHeader,$EventText,$EventArray[0],$Idx
   $Idx = 0
   $CheckEventLog = $DateTime
   $LogDT = $DateTime + '.000000+120'
   $Qry = "Select * From Win32_NTLogEvent Where Logfile = '" + $Log + "' And TimeWritten > '" + $LogDT + "'"
   Select
      Case VarType($Type) = 8
         $Qry = $Qry + " And EventType = '" + $Type + "'"
      Case VarType($Type) & 8192
         $Qry = $Qry + " And (EventType = '" + $Type[0] + "'"
         For $i = 1 To UBound($Type)
            $Qry = $Qry + " Or EventType = '" + $Type[$i] + "'"
         Next
         $Qry = $Qry + ")"
   EndSelect
   If VarType($OmitSource) & 8192
      For Each $Source In $OmitSource
         $Qry = $Qry + " And SourceName <> '" + $Source + "'"
      Next
   EndIf
   $oEventLog = GetObject("winmgmts:\\" + $Server + "\root\cimv2")
   If @Error
      Exit 1
   EndIf
   $Events = $oEventLog.ExecQuery("$Qry")
   For Each $Event In $Events
      $LogDT = Left("" + $Event.TimeWritten,14)
      If $LogDT < $DateTime
         Return
      EndIf
      If $LogDT > $CheckEventLog
         $CheckEventLog = $LogDT
      EndIf
      $EventHeader = 'Server: ' + $Server + @CRLF
      $EventHeader = $EventHeader + 'Log: ' + $Log + @CRLF + @CRLF
      $EventHeader = $EventHeader + 'Time: ' + FormatDate(Left($LogDT,8)) + ' ' + FormatTime(Right($LogDT,6)) + @CRLF + @CRLF
      $EventText = 'Source: ' + $Event.SourceName + @CRLF
      $EventText = $EventText + CleanLine("" + $Event.message) + @CRLF
      $InsertionStrings = $Event.InsertionStrings
      If VarType($InsertionStrings) & 8192
         $WrtHead = 1
         For Each $IString In $InsertionStrings
            $Line = CleanLine("" + $IString)
            If $Line
               If $WrtHead
                  $EventText = $EventText + @CRLF + 'Insertion string(s):' + @CRLF
                  $WrtHead = 0
               EndIf
               $EventText = $EventText + $Line + @CRLF
            EndIf
         Next
      EndIf
      If AScan($EventArray,$EventText) = -1
         ReDim Preserve $EventArray[$Idx]
         $EventArray[$Idx] = $EventText
         If $AlertMsg
            $AlertMsg = $AlertMsg + @CRLF + @CRLF
         EndIf
         $AlertMsg = $AlertMsg + $EventHeader + $EventText + $SepLin
         If Len($AlertMsg) > 20000
            Return
         EndIf
         $Idx = $Idx + 1
      EndIf
   Next
   Exit 0
EndFunction


Function FormatTime($Time)
   $Time = '' + $Time
   $FormatTime = Left($Time,2) + ':' + SubStr($Time,3,2) + ':' + Right($Time,2)
EndFunction


Function FormatDate($Date)
   $Date = '' + $Date
   $FormatDate = Left($Date,4) + '/' + SubStr($Date,5,2) + '/' + Right($Date,2)
EndFunction


Function CleanLine($Line)
   Dim $i,$Ch,$ChNum

   $CleanLine = ''
   For $i = 1 To Len($Line)
      $Ch = SubStr($Line,$i,1)
      $ChNum = Asc($Ch)
      If $ChNum > 32 And $ChNum < 255
         $CleanLine = $CleanLine + $Ch
      Else
         $CleanLine = RTrim($CleanLine) + ' '
      EndIf
   Next
   $CleanLine = RTrim($CleanLine)
EndFunction


Ini-files used by DomCheck.kix
The files must be placed in the same directory as DomCheck.kix

DomCheck.ini
Code:

;Global settings for DomCheck.kix
[Global]
;Seconds betwen checks
SleepTime=90
;Seconds betwen eventlog checks
SleepTimeLog=3600

;TimeOut: Maxtime for replytime from ping in milliseconds
;If no reply, timeout is reported in TimeOut.log
TimeOut=500
;Retry: Maxtime for reply on second check if first ping fails
;If no reply, mails and netalerts are sent
Retry=2000

;Fast: Number (msecs) to indicate witch icon to display
;Reply time < Fast : Green icon
;Reply time >= Fast: Yellow icon
;Timeout           : Red icon
Fast=10

;MailAdr: EMail-adresses to send timeout alerts to
[MailAdr]
Admin@Company.com=1
User@Company.com=1

;NetAlerts: Workstations to receive alerts via Net Send
[NetAlerts]
WS015=1
USER7=1

;LogMailAdr: EMail-adresses to receive alerts from eventlogs/diskchecks
[LogMailAdr]
Admin@Company.com=1

;LogAlerts: Workstations to receive alerts from eventlogs/diskchecks via Net Send
[LogAlerts]
WS015=1

[Mail]
MailServer=YourMailserver.YourDomain.com

;Hosts: IP-adresses to check
;If the IP-adress can be found via WINS/DNS Name can be used instead of IP-Addr
[Hosts]
KiXtart bulletinboard=KiXtart.org
;Displayname=DNS/WINS name
KiXtart scripts=81.17.37.55
;Displayname=IP-Addr

;Servers
Server1=Server1
Server2=Server2
Server3=Server3

;Routers, typically not in WINS/DNS, so IP-Addr is used
Router1=10.1.1.1
Remote RTR=221.100.1.4

;Subnet, typically not in WINS/DNS, so IP-Addr is used
Subnet1-SW1=10.1.0.0
Subnet1-SW2=10.1.0.1
Subnet2-SW1=10.1.1.0

;Servers to check
[Servers]
Server1=x
;Ini-file Server1.ini must exist in scriptdir
;See Server1.ini for details
Server2=x
;Ini-file Server2.ini must exist in scriptdir
Server3=x
;Ini-file Server3.ini must exist in scriptdir


Server1.ini
Code:

[Drives]
;Drivename=Min disk available in kb
;If the avilable diskspace is less than the alert value mails/netalerts are sent
C=500.000
D=3.000.000

[CheckLogs]
;Comma separated list of eventlogs to check for Errors/warnings
Logs=Application,System

[Application]
;SourceNames to ignore in application log - CASE SENSITIVE
KXRpc=1

[Security]
;SourceNames to ignore in security log - CASE SENSITIVE

[System]
;SourceNames to ignore in system log - CASE SENSITIVE
Print=1
TermServDevices=1


Important
The script should be run from NT4+
You should not check eventlogs on OS's < Win2k because the query function on NT4 always returns all entries from todays eventlog. (Slooow)
The OS-language of the server should be English.

Notes
This has been a work in progress for a long time.
I have a consolebased version working on my LAN, But i thought this was a chance to check the wonders of KiXforms Wink

BTW my initial script was inspired by a script posted by Bryce on KiXtart.org long time ago.

If you have had the patience to read the post til here and maybe even tried the script. I would like any suggestions for improvements.

I know the hurdle is that you have to install an extra COM interface. But the mail and ping options from DynoCOM are free.

-Erik


Last edited by kholm on Thu May 22, 2003 8:26 pm; edited 1 time in total
Back to top
View user's profile Send private message
Sealeopard
KiXforms Aficionado
KiXforms Aficionado


Joined: 05 Mar 2003
Posts: 436
Location: Boston, MA

PostPosted: Thu May 22, 2003 12:48 pm    Post subject: Reply with quote

Take a look at the ReadEventlog UDF for a more advanced way to read selective entries form a local/remote eventlog.
_________________
Jens

'There are two kinds of vessels, submarines and targets.'
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Jochen
KiXforms Devotee
KiXforms Devotee


Joined: 05 Mar 2003
Posts: 1204
Location: Stuttgart, Germany

PostPosted: Thu May 22, 2003 1:39 pm    Post subject: Reply with quote

Apart from that,

Welcome Erik !!!

Already wondered where you've been Mr. Green

_________________
Jochen

Tell me, and I will forget.
Show me, and I may remember.
Involve me, and I will understand.
Back to top
View user's profile Send private message MSN Messenger
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Thu May 22, 2003 2:28 pm    Post subject: Reply with quote

Erik, can you give me (us) the short description of how to set this up in my environment - is it possible to just run this from an NT4 wkstn and monitor another NT4 workstation ? What settings do I have to make in the INI files to do this ... please remember - im a NETWORK DUMMY so talking about ROUTERS and IP's and SUBNETS goes way over my head.
Back to top
View user's profile Send private message
kholm
KiXforms Novice
KiXforms Novice


Joined: 22 May 2003
Posts: 4

PostPosted: Thu May 22, 2003 8:23 pm    Post subject: Reply with quote

Shawn, a very short ini-file to get startet.

DomCheck.ini
Code:

[Global]
SleepTime=30
SleepTimeLog=600

TimeOut=500
Retry=2000

Fast=20

[NetAlerts]
WkSta=1
;Replace WkSta with your workstation name

[Hosts]
KiXtart bulletinboard=KiXtart.org
;Displayname=DNS/WINS name

KiXtart scripts=81.17.37.55
;Displayname=IP-Addr

KiXforms.org=KiXforms.org

;Add your own list of servers/workstations to check
; Description = IP-address or name resolved by WINS/DNS
;
; The valuename is used as description to show on the screen and send in alert messages
; The value is the address to ping
; Server1 = ServerName
; Server2 = 10.1.1.120


This dosn't use the servercheck possibilities, so separate ini-files for each server isn't needed.
But it wil show the graphics Wink



BTW: Is it correct that i should use:

For $Num = 0 To $lstView.Items.Count - 1

to enumerate all instances in a ListView object ?


-Erik
Back to top
View user's profile Send private message
kholm
KiXforms Novice
KiXforms Novice


Joined: 22 May 2003
Posts: 4

PostPosted: Thu May 22, 2003 8:49 pm    Post subject: Reply with quote

I have reposted the original script.

The original script sent all events from the checked logs.
The script now only checks for errors and warnings.

It now checks on EventType instead of Type, so the OS-language of the checked ws is irrellevant.

A litle more info:
If the same error/warning has occurred multible times, only one is sent.


-Erik
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Thu May 22, 2003 10:26 pm    Post subject: Reply with quote

Brilliant - works great. I tried setting it up at the office earlier today with very poor results - mostly my own fault. Thought I would have more to comment on because I didn't have the DynuCOM component installed and the form was acting up a little bit. Once you gave me the proper INI and I got DynuCOM installed, it works flawless so comments right now.

For $Num = 0 To $lstView.Items.Count - 1

to enumerate all instances in a ListView object ? Well if your inclined, might want to try a straight for-each-in-next type enum, like so:

For Each $Item In $lstView.Items
? "Text=" $Item.Text
Next

Not all collections can be enumerated at this time. But the Items collection is one of them. Guess at the end of the day, either one works and for-each-in-next is a nice to have.

-Shawn
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Script Archive All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group