Monitoring GB free on mapped Windows drive

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Re: Monitoring GB free on mapped Windows drive

Post 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
Nagios XI 5.8.1
https://outsideit.net
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Monitoring GB free on mapped Windows drive

Post 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)
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Re: Monitoring GB free on mapped Windows drive

Post 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?
Nagios XI 5.8.1
https://outsideit.net
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: Monitoring GB free on mapped Windows drive

Post 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?
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Re: Monitoring GB free on mapped Windows drive

Post 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?
Nagios XI 5.8.1
https://outsideit.net
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Monitoring GB free on mapped Windows drive

Post 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.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: Monitoring GB free on mapped Windows drive

Post 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
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Re: Monitoring GB free on mapped Windows drive

Post 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.
Nagios XI 5.8.1
https://outsideit.net
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Monitoring GB free on mapped Windows drive

Post 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.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Re: Monitoring GB free on mapped Windows drive

Post 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:
Nagios XI 5.8.1
https://outsideit.net
Locked