OP5 plugin example in powershell

If you want to monitor your windows server uptime in OP5. Run from NSClient++ on all hosts you want to monitor uptime on.

param
(
	[parameter(Mandatory = $true)]
	[int]$w,
	[parameter(Mandatory = $true)]
	[int]$c
)
function Get-Uptime
{
	$os = Get-WmiObject win32_operatingsystem
	$uptime = (Get-Date) - ($os.ConvertToDateTime($os.lastbootuptime))
	return $Uptime
}
$os = Get-CimInstance Win32_OperatingSystem | Select-Object  Caption | ForEach{ $_.Caption }
$uptime = Get-Uptime

if ( $uptime.Days -gt $c)
{
	Write-Host Write-Host "CRITICAL Uptime:" $Uptime.Days "days"
	exit 2

}
if ($uptime.Days -gt $w)
{
	Write-Host Write-Host "WARNING Uptime:" $Uptime.Days "days"
	exit 1

}
if ($uptime.Days -lt $w)
{
	Write-Host "OK" $Uptime.Days "days uptime"
	Write-Host "OS: $os"
	exit 0
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.