Advertisement
Guest User

Untitled

a guest
Feb 1st, 2017
1,789
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sFrom    = "Admon SQL Server"
  2. sAddress = "10.0.0.5"
  3.  
  4. Set oFSO    = CreateObject("Scripting.FileSystemObject")
  5. Set oHTTP   = CreateObject("Microsoft.XmlHttp")
  6. Set oWMI    = GetObject("winmgmts:\\.\root\CIMV2")
  7. Set Item    = oWMI.ExecQuery("SELECT * FROM Win32_PingStatus WHERE Address = '" & sAddress & "'", "WQL", &H10 + &H20)
  8.  
  9. Set F = oFSO.OpenTextFile("C:\scripts\pinglog.csv", 8, True)
  10.  
  11. For Each oPing In Item
  12.    
  13.     sDate = Day(now) & "/" & Month(now) & "/" & Year(now)
  14.     sTime = Hour(now) & ":" & Minute(now) & ":" & Second(now)
  15.    
  16.     If oPing.StatusCode = 0 Then
  17.         F.WriteLine sDate & ";" & sTime & ";" & oPing.Address & ";" & oPing.ProtocolAddress & ";" & oPing.BufferSize & ";" & oPing.ResponseTime & ";" & oPing.ResponseTimeToLive & ";" & oPing.ReplyInconsistency
  18.     Else
  19.         F.WriteLine sDate & ";" & sTime & ";" & oPing.Address & ";error;error;error;error;error"
  20.         Call SendMail("Ping Error!", "Your device " & sAddress & " looks offline" & sDate & " - " & sTime)
  21.         Call SendTelegram("Ping from " & sFrom & ": " & sAddress & " looks offline")
  22.     End if
  23. Next
  24.  
  25. F.Close
  26.  
  27. Function SendTelegram(txtBody)
  28.     oHTTP.Open "GET", "http://insert_your_telegram_server/telegram.asp?msg=" & txtBody, False
  29.     oHTTP.setRequestHeader "Cache-Control", "no-cache"
  30.     oHTTP.Send ""
  31. End Function
  32.  
  33. Function SendMail(txtSubject, txtBody)
  34.     oCDO = "http://schemas.microsoft.com/cdo/configuration/"
  35.     Set oMSG = CreateObject("CDO.Message")
  36.         oMSG.Subject = txtSubject
  37.         oMSG.From = "robot@mydomain.com"
  38.         oMSG.To = "sysadmin@mydomain.com"
  39.         'oMSG.Cc = ""
  40.         oMSG.TextBody = txtBody
  41.         With oMSG.Configuration.Fields
  42.             .Item (oCDO & "sendusing") = 2
  43.             .Item (oCDO & "smtpserverport") = 25
  44.             .Item (oCDO & "smtpauthenticate") = 1
  45.             .Item (oCDO & "smtpconnectiontimeout") = 60
  46.             .Item (oCDO & "sendusername") = "robot@mydomain.com"
  47.             .Item (oCDO & "sendpassword") = "p4ssw0rd"
  48.             .Item (oCDO & "smtpserver") = "mail.mydomain.com"
  49.             .Item (oCDO & "smtpusessl") = False
  50.             .Update
  51.         End With
  52.     oMSG.Send
  53. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement