Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sFrom = "Admon SQL Server"
- sAddress = "10.0.0.5"
- Set oFSO = CreateObject("Scripting.FileSystemObject")
- Set oHTTP = CreateObject("Microsoft.XmlHttp")
- Set oWMI = GetObject("winmgmts:\\.\root\CIMV2")
- Set Item = oWMI.ExecQuery("SELECT * FROM Win32_PingStatus WHERE Address = '" & sAddress & "'", "WQL", &H10 + &H20)
- Set F = oFSO.OpenTextFile("C:\scripts\pinglog.csv", 8, True)
- For Each oPing In Item
- sDate = Day(now) & "/" & Month(now) & "/" & Year(now)
- sTime = Hour(now) & ":" & Minute(now) & ":" & Second(now)
- If oPing.StatusCode = 0 Then
- F.WriteLine sDate & ";" & sTime & ";" & oPing.Address & ";" & oPing.ProtocolAddress & ";" & oPing.BufferSize & ";" & oPing.ResponseTime & ";" & oPing.ResponseTimeToLive & ";" & oPing.ReplyInconsistency
- Else
- F.WriteLine sDate & ";" & sTime & ";" & oPing.Address & ";error;error;error;error;error"
- Call SendMail("Ping Error!", "Your device " & sAddress & " looks offline" & sDate & " - " & sTime)
- Call SendTelegram("Ping from " & sFrom & ": " & sAddress & " looks offline")
- End if
- Next
- F.Close
- Function SendTelegram(txtBody)
- oHTTP.Open "GET", "http://insert_your_telegram_server/telegram.asp?msg=" & txtBody, False
- oHTTP.setRequestHeader "Cache-Control", "no-cache"
- oHTTP.Send ""
- End Function
- Function SendMail(txtSubject, txtBody)
- oCDO = "http://schemas.microsoft.com/cdo/configuration/"
- Set oMSG = CreateObject("CDO.Message")
- oMSG.Subject = txtSubject
- oMSG.From = "robot@mydomain.com"
- oMSG.To = "sysadmin@mydomain.com"
- 'oMSG.Cc = ""
- oMSG.TextBody = txtBody
- With oMSG.Configuration.Fields
- .Item (oCDO & "sendusing") = 2
- .Item (oCDO & "smtpserverport") = 25
- .Item (oCDO & "smtpauthenticate") = 1
- .Item (oCDO & "smtpconnectiontimeout") = 60
- .Item (oCDO & "sendusername") = "robot@mydomain.com"
- .Item (oCDO & "sendpassword") = "p4ssw0rd"
- .Item (oCDO & "smtpserver") = "mail.mydomain.com"
- .Item (oCDO & "smtpusessl") = False
- .Update
- End With
- oMSG.Send
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement