Page 2 of 3

Re: Monitoring GB free on mapped Windows drive

Posted: Tue Mar 11, 2014 7:09 am
by WillemDH
For those who would be interested:

Code: Select all

Param(
[Parameter(Mandatory=$true)][string]$dfspad,
[Parameter(Mandatory=$true)][int]$quota,
[Parameter(Mandatory=$true)][double]$warningperc,
[Parameter(Mandatory=$true)][double]$criticalperc
)
$sumMB = 0
$warningMB = 0
$criticalMB = 0
$status = 0
$folderlist = Get-ChildItem $dfspad -Recurse -ErrorAction SilentlyContinue | Measure-Object -property length -sum
$sumMB = [System.Math]::Round($folderlist.sum / 1MB, 2)
$warningMB = $quota * $warningperc
$criticalMB = $quota * $criticalperc
echo "warningperc: $warningperc"
echo "criticalperc: $criticalperc"
echo "quota: $quota"
echo "sumMB: $sumMB"
echo "warning: $warningMB"
echo "critical: $criticalMB"


if ($sumMB -ge $criticalMB) {
	$status = 2
	echo "$dfspad has exceeded it's critical threshold!"
	echo "Size = $sumMB MB, Critical Threshold = $criticalMB MB"
}
elseif ($sumMB -ge $warningMB) {
	$status = 1
	echo "$dfspad has exceeded it's warning threshold!" 
	echo "Size = $sumMB MB, Warning Threshold = $criticalMB MB"
}
else {
	echo "$dfspad has not exceeded any thresholds."
	echo "Size = $sumMB MB"
}

# echo "status: $status"

Write-Output "$sumMB MB | Used_Storage=$sumMB"

# $perfdata = "$sumMB MB | Used_Storage=$sumMB"
#$return.output = "$sumMBMB | Used_Storage=$sumMB"
#$outputstring=$return.output
#Write-Output "$outputstring"
Exit $status
I did not post this yet on Exchange, as the script needs some refinement. For big volumes, it tends to run quite long, so timeout needs to be set really long (120 sec)

In fact it should be run by the client and then sent to Nagios, but I didn't found the time to test this yet.

Grtz

Re: Monitoring GB free on mapped Windows drive

Posted: Tue Mar 11, 2014 10:00 am
by sreinhardt
Cool script Willem! I would agree if this takes a while to run, using as a passive check would be ideal. The only other item I might note, would be to alter the echo's to write-host so that you stick with fully powershell compliant syntax and don't call external binaries unless absolutely needed. (I'm just not a fan of mixing cmd\vbs and powershell if at all avoidable)

Re: Monitoring GB free on mapped Windows drive

Posted: Tue Mar 11, 2014 10:08 am
by WillemDH
Good remark. I wrote this script in September last year and my Powershell knowledge has been growing since. I'll try to find some time, update the script and upload it on exchange.
I have zero experience with passive running Powershell scripts. Any guidance or nsclient.ini examples?

Re: Monitoring GB free on mapped Windows drive

Posted: Tue Mar 11, 2014 1:09 pm
by slansing
Hmm, for actually passively running plugins, I would recommend NRDP, or NCPA which has NRDP included with it. Have you looked into this?

Re: Monitoring GB free on mapped Windows drive

Posted: Tue Mar 11, 2014 4:56 pm
by WillemDH
No, sorry, didn't use NRDP nor NCPA. I'll try this asap.. So I can schedule Powershell script execution with NCPA and return results to Nagios?

Re: Monitoring GB free on mapped Windows drive

Posted: Tue Mar 11, 2014 4:58 pm
by sreinhardt
Yes, you should be able to do this via nsclient and nrdp\nsca as well if you wish to stay on that agent. Off hand I am not 100% sure, however I doubt the configurations are far from the active check config.

Re: Monitoring GB free on mapped Windows drive

Posted: Tue Mar 11, 2014 5:02 pm
by slansing
Side note, yeah you should totally be able to use the plugin with NCPA, one of the downsides to nsclient is it only supports nrpe, check_nt, and nsca, there seems to be limited NRDP support, however it is a third party monitoring tool that is disconnected from our development cycle:

http://assets.nagios.com/downloads/ncpa ... ation.html

Re: Monitoring GB free on mapped Windows drive

Posted: Tue Mar 11, 2014 5:07 pm
by WillemDH
Well, as long as there is no realtime eventlog monitoring in NCPA, I'm forced to keep using nsclient. monitoring eventlogs is critical for us.
Is running both NCPA and nsclient on one server advisable? I think it's possible to schedule Powershell script exection with nsclient too. Just didn't have the time to test this.

Re: Monitoring GB free on mapped Windows drive

Posted: Wed Mar 12, 2014 10:17 am
by sreinhardt
It shouldn't hurt a thing to run them both if you wish. Also agreed, you should be able to schedule them passively with nsclient or ncpa if you wish. The nice thing about ncpa, is it definitely would not rely on the task scheduler, and you could decide to only run the passive service if you wished. One possibility, if you wanted you can setup event logs with snmptraps, but the question there is if the change is worth the additional work for you.

Re: Monitoring GB free on mapped Windows drive

Posted: Wed Mar 12, 2014 12:33 pm
by WillemDH
Already put quite a bit of work into this realtime eventlog monitoring. One of the next scripts I'll write will hopefully be able to exclude event id's with a quick action. So i'm starting with a fresh nsclient.ini with some default exclusions and will add more excluded events when needed. At the moment I'm still working with a few versions of nsclient.ini which are distributed each night to all servers. if I need to exclude an extra event, I add it to the respective template.
But first I need to find some time :roll: