Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
ruffsense
Posts: 140 Joined: Thu Apr 11, 2013 12:40 am
Post
by ruffsense » Fri Nov 25, 2016 3:12 pm
I have created a script for nagios but now i want to change the $folder and $file $MaxAgeMinutes into $args[0] - $args[1] - $args[2].
So i can pass arguments in my nsclient.ini
test = cmd /c echo scripts\test.ps1 "$ARG1$" "$ARG2$" "$ARG3$"; exit($lastexitcode) | powershell.exe -command -
Code: Select all
$folder = 'c:\temp\'
$file = 'CGO.csv'
$MaxAgeMinutes = 1440
# Process Limit
$Limit = (Get-Date).AddMinutes((-1 * $MaxAgeMinutes))
$path = "$folder\$file"
if (Test-Path $path)
{
if ((Get-Item $Path).LastWriteTime -lt $limit)
{
echo "WARNING status - $file is older than 24 hours."
exit 1 #returns warning status
}
else
{
echo "OK status – file is OK"
exit 0 #Return OK status
}
}
else
{
echo "CRITICAL status – file $file doesn’t exist"
exit 2 #returns critical status
}
Last edited by
dwhitfield on Mon Nov 28, 2016 5:21 pm, edited 1 time in total.
Reason: marking with green check mark
I don't insult, I diagnose.
ruffsense
Posts: 140 Joined: Thu Apr 11, 2013 12:40 am
Post
by ruffsense » Mon Nov 28, 2016 3:45 pm
thnx.
If any one is looking for a check_file powershell script with arguments that checks if a file excist or is older then 24ours. Here you go.
Code: Select all
function check_file()
{
$folder = "$($args[0])"
$file = "$($args[1])"
$MaxAgeMinutes = 1440
# Process Limit
$Limit = (Get-Date).AddMinutes((-1 * $MaxAgeMinutes))
$path = "$folder\$file"
if (Test-Path $path)
{
if ((Get-Item $Path).LastWriteTime -lt $limit)
{
echo "WARNING status - $file is older than 24 hours."
exit 1 #returns warning status
}
else
{
echo "OK status – file is OK"
exit 0 #Return OK status
}
}
else
{
echo "CRITICAL status – file $file doesn’t exist"
exit 2 #returns critical status
}
}
I don't insult, I diagnose.
dwhitfield
Former Nagios Staff
Posts: 4583 Joined: Wed Sep 21, 2016 10:29 am
Location: NoLo, Minneapolis, MN
Contact:
Post
by dwhitfield » Mon Nov 28, 2016 4:31 pm
Thanks so much for posting!
It looks like your issue is resolved. Is that correct? Is it ok to lock the thread?
ruffsense
Posts: 140 Joined: Thu Apr 11, 2013 12:40 am
Post
by ruffsense » Mon Nov 28, 2016 5:20 pm
you can lock it.
I don't insult, I diagnose.