I have the following PS-Script which works well:
$sb = { if (!(get-process 'LogikWebserver').Responding) { write-host "1:Not Responding" ; exit 1 } else { write-host "0:OK" ; exit 0 }} $File = "C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXE\AdminSystem.txt" [Byte[]] $key = (1..16) $pw = Get-Content $File | ConvertTo-SecureString -Key $key $admin = "domain\admin" $cred = New-Object System.Management.Automation.PSCredential -argumentlist $admin,$pw Invoke-Command -scriptblock $sb -computername COMP -credential $cred
I now want to set the status of my sensor to "error" when my script returns "Not Responding", and I want it to send me an E-Mail.
I know how to send an E-Mail directly from the script, but I'd rather have a PRTG-Mail just with my status code. How do I do that?
Thanks!
Article Comments
Hi Stephan
OK, i'll go the PowerShell way then. But can you explain a little further (sorry i'm a newbie to PRTG):
When I have a sensor for e.g check RAM on Computer X, and the sensor says "RAM for Computer X is not OK anymore", then the state of the sensor is in error state (red color in PRTG) and PRTG then sends a notification to us with "this sensor just turned red, do something about it"
Right now, when my Script returns "Not Responding" the sensor stays green. can't i like give it an ID so that PRTG knows this sensor has to go in error state now and then send an e-mail notification because the sensor is in error state?
Right now, when the sensor is always in OK-state (green), then the availability and stuff like this will always be 100%.
Sorry for my rusty english, I hope you understood what I was trying to ask. Otherwise i'll go for the german-forum next time ;-)
tschüss, Simon
Sep, 2016 - Permalink
Hi Simon,
Wir können hier auch gerne auf deutsch schreiben ;) Was genau gibt dein Script denn zurück und welchen Exit-Code verwendet es? Zur Erklärung:
- Exit-Code 0: Alles okay
- Exit-Code 1: Warnung
- Exit-Code 2-5: Fehler
Grundsätzlich gibt's für Arbeitsspeicher, genauso wie CPU, Platte, usw., fertige Sensoren :)
Sep, 2016 - Permalink
Hi Stephan
Ah gut, Deutsch ist besser :). Ja, für Arbeitsspeicher etc. benutzen wir die vorgefertigten Sensoren. Mein Problem ist, dass ich nun einen Prozess auf sein Responding Property überprüfen muss, da der Prozess nicht wirklich abstürzt, sondern einfach nur hängen bleibt. Daher muss ich auf PowerShell zurückgreifen - oder gibt es dafür auch einen vorgefertigten Sensor?
Nun möchte ich gerne dass ich nur den Fehlerstatus setze, diesen an PRTG mit dem Exit-Code zurückmelde und sich PRTG dann wie ein vorgefertigter Sensor verhält, und eine Fehlermeldung in Form einer E-Mail auslöst. Doch egal welchen Exit-Code ich zurückgebe, der Sensor bleibt immer auf "OK" mit grünem Haken. Er wechselt in der übersicht zwar wie im Skript vorgesehen von "OK" zu "Not Responding", aber der wirkliche Status bleibt auf "ok", anstatt dass er auf "Fehler" wechselt.
Wenn mein Vorhaben so nicht funktioniert, dann sende ich die Mail einfach per Skript und danke dir schon mal für deine Hilfe :)!
gruss Simon
Sep, 2016 - Permalink
Ah ich seh das Problem - du gibst not reponsing usw. auf dem Zielhost aus, PRTG kriegt davon garnichts mit.
Mach mal wie folgt:
$sb = { if (!(get-process 'LogikWebserver').Responding) { return false; } else { return true; } } $File = "C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXE\AdminSystem.txt" [Byte[]] $key = (1..16) $pw = Get-Content $File | ConvertTo-SecureString -Key $key $admin = "domain\admin" $cred = New-Object System.Management.Automation.PSCredential -argumentlist $admin,$pw $Result = (Invoke-Command -scriptblock $sb -computername COMP -credential $cred) if ($result) { write-host "0:OK" ; exit 0 } else { write-host "1:Not Responding" ; exit 1 }
Das Kommando gibt dann entsprechend $true oder $false zurück und am Ende wird entsprechend die Nachricht ausgegeben inkl. Exit-Code :)
Sep, 2016 - Permalink
You'll have to go the powershell way to send mails, PRTG notifications can't be triggered other than via the test option which doesn't replace any placeholders and renders them basically useless :)
Sep, 2016 - Permalink