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

An Updated version of Server Ping (more things to play with)

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


Joined: 30 Dec 2003
Posts: 366
Location: Arizona

PostPosted: Fri Feb 18, 2005 11:27 pm    Post subject: An Updated version of Server Ping (more things to play with) Reply with quote

Code:
Break On
SetConsole("hide")
;Basic Network Monitor
;
;Written By Wayne A Kimball
;
;
;Requires KixStart V 4.23
;Requires KixForms V 2.3
;Requires Blat.exe
;Requires text file with
;all entries that you want to monitor
;Text File is named "ALLDEV.TBL"
;Written in the Format of
;++++++++++++++++++++++++++++++++++++
;DNS Name,What TabPage to display On
;++++++++++++++++++++++++++++++++++++
;Example
;
;   MailServer.Domain.Com,3
;
;

;Start By creating a form Object
$System = CreateObject("Kixtart.System")
$Form = $System.Form()

;Add a Form Collection Control to it
$TabControl1 = $Form.TabControl()

; Populates TabControl1 with four tab pages ...
;The Page # corresponds to the number in the file
$TabPage1 = $TabControl1.TabPages.Add("Routers")
$TabPage2 = $TabControl1.TabPages.Add("Switches")
$TabPage3 = $TabControl1.TabPages.Add("Servers")
$TabPage4 = $TabControl1.TabPages.Add("Misc")

;************Label at startup
$Label1 = $Form.Controls.Label()
$Label1.BackColor = 212,208,200
$Label1.Height = 23
$Label1.Left = 0
$Label1.Text = "What would you like to monitor"
$Label1.Top = 0
$Label1.Width = 200

;*************Declerations

Global $c, $alldev[], $Ucount, $rc, $l, $t, $EName, $CheckArray[], $SWidth, $s, $r
Global $StatArray[], $Temp[], $TabArray[], $t1t, $t2t, $t3t, $t4t, $t1l, $t2l, $t3l, $t4l

$t1l = 5
$t1t = 30
$t2l = 5
$t2t = 30
$t3l = 5
$t3t = 30
$t4l = 5
$t4t = 30
$rc = SetOption(NoVarsInStrings, On)
$SWidth = $Form.Screen.Width - 50

;************Build an array with all of the devices in it
Open(1,@SCRIPTDIR +"\alldev.tbl",2)
   $c = 0
   While @ERROR = 0
      ReDim Preserve $alldev[$c]
      ReDim Preserve $TabArray[$c]
      $s = ReadLine(1)
      If $s <> ""
         $temp = Split($s,",")
         $alldev[$c] = $temp[0]
         $TabArray[$c] = $temp[1]
         $c =$c + 1
      EndIf
   Loop
Close(1)
$Ucount = UBound($alldev)

;Call the routine to build out the form

$c=0
For Each $element in $alldev
BuildCheck($element)
Next

;Adjust the height / Width so it is visible
$Form.Height = $t + 150
$Form.Width = $SWidth
$TabControl1.Location = 10, 30
$TabControl1.Size = $form.width - 25, $t + 50

;Add some buttons now that we have basic form  built
;Buttons needed
$ButtonSA = $Form.Controls.Button()
$ButtonSA.Height = 23
$ButtonSA.Left = 205
$ButtonSA.Text = "Select All"
$ButtonSA.Top = $t + 90
$ButtonSA.Width = 75
$ButtonSA.Onclick = "SA()"

$ButtonCA = $Form.Controls.Button()
$ButtonCA.Height = 23
$ButtonCA.Left = 285
$ButtonCA.Text = "Clear All"
$ButtonCA.Top = $t + 90
$ButtonCA.Width = 75
$ButtonCA.Onclick = "CA()"

$ButtonSGO = $Form.Controls.Button()
$ButtonSGO.Height = 23
$ButtonSGO.Left = 365
$ButtonSGO.Text = "Monitor"
$ButtonSGO.Top = $t + 90
$ButtonSGO.Width = 75
$ButtonSGO.Onclick = "SGO()"

$ButtonSTA = $Form.Controls.Button()
$ButtonSTA.Height = 23
$ButtonSTA.Left = 125
$ButtonSTA.Text = "Select Tab"
$ButtonSTA.Top = $t + 90
$ButtonSTA.Width = 75
$ButtonSTA.Onclick = "STA()"



$Form.Show
While $Form.Visible
 $=Execute($Form.DoEvents)
Loop

Exit 1

;
;^^^^^^^^^^^^^^Functions^^^^^^^^^^^^^^^^^^
;
;*************Build Form with all of the names

Function BuildCheck($EName)
   If $Ename <>""
   $rc = Execute("$CheckBox"+$c+" = $Tabpage"+$Tabarray[$c]+".CheckBox()")
   $rc = Execute("$CheckBox"+$c+".BackColor = 212,208,200")
   $rc = Execute("$CheckBox"+$c+".CheckAlign = 16")
   $rc = Execute("$CheckBox"+$c+".Height = 24")
   $rc = Execute("$CheckBox"+$c+".Text = +$Ename")
   $rc = Execute("$CheckBox"+$c+".Width = 150")
      Select
         Case $TabArray[$c] = 1
            $rc = Execute("$CheckBox"+$c+".Left = "+$t1l)
            $rc = Execute("$CheckBox"+$c+".Top = "+$t1t)
            $t1Count = $t1Count + 1
            $t1l = $t1l + 150
               If $t1l > $SWidth - 149
                  $t1t = $t1t + 25
                  $t1l = 5
               EndIf
         Case $TabArray[$c] = 2
            $rc = Execute("$CheckBox"+$c+".Left = "+$t2l)
            $rc = Execute("$CheckBox"+$c+".Top = "+$t2t)
            $t2Count = $t2Count + 1
               $t2l = $t2l + 150
               If $t2l > $SWidth - 149
                  $t2t = $t2t + 25
                  $t2l = 5
               EndIf
         Case $TabArray[$c] = 3
            $rc = Execute("$CheckBox"+$c+".Left = "+$t3l)
            $rc = Execute("$CheckBox"+$c+".Top = "+$t3t)
            $t3Count = $t3Count + 1
            $t3l = $t3l + 150
               If $t3l > $SWidth - 149
                  $t3t = $t3t + 25
                  $t3l = 5
               EndIf
         Case $TabArray[$c] = 4
            $rc = Execute("$CheckBox"+$c+".Left = "+$t4l)
            $rc = Execute("$CheckBox"+$c+".Top = "+$t4t)
            $t4Count = $t4Count + 1
            $t4l = $t4l + 150
               If $t4l > $SWidth - 149
                  $t4t = $t1t + 25
                  $t4l = 5
               EndIf
      EndSelect
   $c=$c+1
   EndIf
   
If $t1t > t2t
   $t = $t1t
   Else
   $t = $t2t
EndIf

If $t < $t3t
   $t = $t3t
EndIf

If $t < $t4t
   $t = $t4t
EndIf

If $t1l > t2l
   $l = $t1l
   Else
   $l = $t2l
EndIf

If $l < $t3l
   $l = $t3l
EndIf

If $l < $t4l
   $l = $t4l
EndIf
EndFunction

;*****************Select All entries
Function SA()
   For $c = 0 to $Ucount -1
      $rc=Execute("$Checkbox"+$c+".Checked = True")
   Next
EndFunction

;****************Clear All entries
Function CA()
   For $c = 0 to $Ucount -1
      $rc=Execute("$Checkbox"+$c+".Checked = False")
   Next

EndFunction

;******************Select all on tab
Function STA()
$r = $TabControl1.SelectedIndex()
   Select
      Case $r = 0
          For $c = 0 to $Ucount
             If $TabArray[$c] = 1
                $rc=Execute("$Checkbox"+$c+".Checked = True")
             EndIf
          Next
      Case $r = 1
          For $c = 0 to $Ucount
             If $TabArray[$c] = 2
                $rc=Execute("$Checkbox"+$c+".Checked = True")
             EndIf
          Next
      Case $r = 2
          For $c = 0 to $Ucount
             If $TabArray[$c] = 3
                $rc=Execute("$Checkbox"+$c+".Checked = True")
             EndIf
          Next
      Case $r = 3
          For $c = 0 to $Ucount
             If $TabArray[$c] = 4
                $rc=Execute("$Checkbox"+$c+".Checked = True")
             EndIf
          Next
   EndSelect
EndFunction

;********************Start********
Function SGO ()

Dim $Result
$Label1.Dispose
$ButtonSA.Dispose
$ButtonCA.Dispose
$ButtonSGO.Dispose
$count = 0
For $c = 0 to $Ucount -1
   $rc=execute("$result=$CheckBox"+$c+".CheckState")
   If $result = 1
         ReDim Preserve $CheckArray[$count]
         $CheckArray[$count]=$alldev[$c]
         $count = $count + 1
   EndIf 
   $rc = Execute("$CheckBox"+$c+".Dispose")
Next
ReDim $StatArray[UBound($Checkarray)]
$TabControl1.Dispose
BuildPing()
EndFunction

;*******************Build the new form
Function BuildPing()
   $t = 5
   $l = 5
   For $c = 0 to UBound($Checkarray)
      $rc=Execute("$Label"+$c+" = $Form.Controls.Label()")
      $rc=execute('$Label'+$c+'.BackColor = Black')
      $rc=Execute("$Label"+$c+".Forecolor = White")
      $rc=Execute("$Label"+$c+".text = $Checkarray[$c]")
      $rc=Execute("$Label"+$c+".Top = $t")
      $rc=Execute("$Label"+$c+".Left = $l")
      $rc=Execute("$Label"+$c+".width = 100")
      $rc=Execute("$Label"+$c+".height = 23")
      $l = $l + 105
      If $l > $SWidth - 80
         $t = $t + 25
         $l = 5
      EndIf
   Next
   $Form.Height = $t + 50
   $Form.Width = $SWidth
   $Form.Text = "Now Monitoring"
   
   $ButtonQ = $Form.Controls.Button()
   $ButtonQ.Height = 23
   $ButtonQ.Left = $l
   $ButtonQ.Text = "Exit"
   $ButtonQ.Top = $t
   $ButtonQ.Width = 75
   $ButtonQ.Onclick = "Ex()"

Ping()
EndFunction

Function Wait()
$Timer = $Form.Controls.Timer

; Interval is set in milliseconds
$Timer.Interval = 600000

$Timer.Ontimer = "Ping()"
EndFunction

Function Ping()
;***********Actually Do the pings
   $c=0
   For Each $Element in $CheckArray   
      $rc=execute('$Label'+$c+'.BackColor = Yellow')
      Shell 'CMD.EXE /c PING '+$Element+' -n 2 | find /i "TTL" >nul'
         If @error = 0
            $rc=execute('$Label'+$c+'.BackColor = Green')
            If $StatArray[$c] > ""
               $StatArray[$c] = ""
            EndIf
         Else
            $rc=Execute('$Label'+$c+'.BackColor = Red')
            Counters($c, $element)
         EndIf
      $=Execute($Form.DoEvents(1))
      $c=$c+1
   Next
Wait()
EndFunction

;**********************Watch for failures and send Page
Function Counters ($index, $element)
   $StatArray[$index] = $StatArray[$index] + 1
      If $StatArray[$index] = 2 or $StatArray[$index] = 6
         Shell "Blat - -Body "+chr(34)+" Alarm From KixMoniter "+$Element+" is not reponding"+ chr(34)+ " -to youremail@@domain.com -s Kix_Alarm"
      EndIf
      If $StatArray[$index] = 6
         $StatArray[$index] = ""
      EndIf
EndFunction

;****************Exit routine************************
Function EX ()
Quit (1)
EndFunction

_________________
Parents were invented to make children happy by giving them something to ignore.
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