Some Powershell tools for Monitors in Dynatrace, and other usage.
This script will check for events based on the parameters given below, it will write the last searched position into an xml file, and will continue from there on the next run.
powershell -file <location of script> -computername <computername> -source <source> -eventid <eventid> -folder <folder> -log <log> -seed_depth <max number of log entries> -instanceid <instance id> -message <message>
powershell -file "c:\scripts\eventlog2.ps1" -source "Outlook" -eventid "63" -folder "c:\scripts\xmllog" -log "Application" -seed_depth 400 -message "*Exchange*" -computername "tarjei-2"
Found no historyfile
Log monitor started at 08/16/2017 16:25:43
Started processing tarjei-2
Processing 400 events.
Index is 1137573
Evaluating message *Exchange*
Found message: The Exchange web service request GetAppManifests succeeded.
Found message: The Exchange web service request GetAppManifests succeeded.
Found message: The Exchange web service request GetAppManifests succeeded.
Found message: The Exchange web service request GetAppManifests succeeded.
Found message: The Exchange web service request GetAppManifests succeeded.
Found message: The Exchange web service request GetAppManifests succeeded.
Found message: The Exchange web service request GetAppManifests succeeded.
Found message: The Exchange web service request GetAppManifests succeeded.
Found message: The Exchange web service request GetAppManifests succeeded.
Found message: The Exchange web service request GetAppManifests succeeded.
Found message: The Exchange web service request GetAppManifests succeeded.
Found message: The Exchange web service request GetAppManifests succeeded.
Found message: The Exchange web service request GetAppManifests succeeded.
Found message: The Exchange web service request GetAppManifests succeeded.
Found message: The Exchange web service request GetAppManifests succeeded.
Found message: The Exchange web service request GetAppManifests succeeded.
Found message: The Exchange web service request GetAppManifests succeeded.
Found message: The Exchange web service request GetAppManifests succeeded.
Found 18 alert events in seconds for eventid 63
------------------------------------------------------------
-eventid
-log "Application" (Application, System or something else)
-path "c:\scripts\xmllog"
-seed_depth 200
These tips are for using the Generic Execution Plugin and monitoring services in that way. ${HOST} is replaced with the server, or servers that are added to the monitor, and they are replaced at run time. All commands should be possible to test in a Powershell window before adding them to the Generic Execution Plugin (GEP).
Command:
ping ${HOST}
Regular Expression:
(.*)Request timed out|Destination host unreachable(.*)
Success Definition:
on no match
Alternative regular expression:
(.*)Reply from(.*)
Success Definition:
on match
Command:
powershell -command "get-service -computername ${HOST} W3SVC"
Regular Expression:
(.*)Stopped|Paused|Running_Pending|Pause_Pending|Stop_Pending|Continue_Pending(.*)
Success Definition:
on no match
Command:
powershell -command "get-service -computername ${HOST} -displayname 'MSSQL*'"
Regular Expression:
(.*)Stopped|Paused|Running_Pending|Pause_Pending|Stop_Pending|Continue_Pending(.*)
Success Definition:
on no match
Command:
powershell -command "Get-Counter -computername ${HOST} -Counter '\LogicalDisk(d:)\% Free Space'"
Command:
powershell -command "@(get-process -computername ${HOST} -ea silentlycontinue W3SVC).count"
Command:
powershell -command "@(get-process -computername ${HOST} -ea silentlycontinue W3SVC).count -gt 1"
Will return True if the number of processes are greater than 1, and will return false, if the number of processes are less than or equal to 1.
Command:
powershell -command "@(get-process -computername ${HOST} -ea silentlycontinue W3SVC).count -eq 1"
Will return True if the number of processes are equal to 1, and will return false, if the number of processes are less than or greater than 1.
Command:
powershell -command "@(get-process -computername ${HOST} -ea silentlycontinue W3SVC).count -lt 1"
Will return True if the number of processes are less than 1, and will return false, if the number of processes are equal to or greater than 1.
Regular Expression:
True
Success Definition:
on match
The command below will check the age of a file, to see whether it is less than 24 hours old. It will return True if that is the case
Command:
powershell -command "(Get-Item '\\${HOST}\c$\path\to\file\logfile.txt').LastWriteTime" -lt (get-date).AddHours(-24)"
Regular Expression:
True
Success Definition:
on match