Quantcast
Channel: THWACK: All Content - Network Performance Monitor
Viewing all articles
Browse latest Browse all 21870

Returning a value and sending it in an email from an Alert run script

$
0
0

Just as the title says, I'm looking to execute a remote script and send the results to a specified inbox automatically. This alert will be triggered when the CPU is at 100% for a few minutes and the script will be run locally by the alert. I have it set to return a message with the processes running and current percent utilized by the processor but I can't figure out if the returned message is then put in some sort of variable I can then have emailed to myself. I'm also working on an alternative if what I think is true; you can't email the results from the alerts manager. Any help or pointing in the right direction would be very much apprecieated. Below is the script I'm working with so far.

 

 

 

Option Explicit
Dim strComputer, intPasses, intPause, objWMIService
Dim objRefresher, colItems, objItem, i, output

Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).

Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM

strComputer = "."
intPasses = 5
intPause = 1000 'milliseconds

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
set objRefresher = CreateObject("WbemScripting.SWbemRefresher")
Set colItems = objRefresher.AddEnum _
    (objWMIService, "Win32_PerfFormattedData_PerfProc_Process").objectSet
objRefresher.Refresh

    For Each objItem in colItems
  'objRefresher.Refresh
  if ((objItem.Name <> "_Total") And (objItem.PercentProcessorTime > 0)) Then
  output = output + vbCrLf & "Name: " & objItem.Name & _
  "  Creating Process ID: " & objItem.CreatingProcessID & _
  "  Percent Processor Time: " & _
  objItem.PercentProcessorTime
  End If
 
    Next

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Example CDO Message"
objMessage.From = """My Name"" <email.address@host.com>"
objMessage.To = "someone@somewhere.com"
objMessage.TextBody = output

'==This section provides the configuration information for the remote SMTP server.

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "ServerIP or DNS Name"

'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic

'Your UserID on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username"

'Your password on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"

'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

'Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True

'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

objMessage.Configuration.Fields.Update

'==End remote SMTP server configuration section==

objMessage.Send


WScript.echo "Message: " & output
WScript.echo "Statistic: 0"


Viewing all articles
Browse latest Browse all 21870

Trending Articles



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