Return Codes? (was RE: Remotely Checking Windows: Mapped Network Drives)

Jason Martin jhmartin at toger.us
Tue Jan 3 23:13:34 CET 2006


On Tue, Jan 03, 2006 at 03:57:40PM -0600, Robert Reeves wrote:
> My script is reporting the following string to NRPE NT and then to
> Nagios:
> CRITICAL U: - Percentage Free = 9% (2200961024/23583522816) 
> WARNING V: - Percentage Free = 16% (5904531456/36124491776) 
> 
> I thought that Nagios looking for OK, WARNING and CRITICAL in the return
The returned output and return code are entirly different. The
output is the STDOUT text and is not parsed by Nagios save for
splitting the text on the first | character and displaying only
the first part. The use of the name 'returncode' in the example
below is bad; in that contect returncode should be named
'output'.

The return code is the return code of the program.  It is passed
by ending the plugin with something like 'exit(0)', exit(1),
exit(2) or exit(3). These are commonly macro'd as
OK,WARNING,CRITICAL, and UNKNOWN, respetively. 

All programs default to exiting return-code 0 (IE OK), which is
why you are getting OK when the text says something else. 

A basic plugin in a shell script would be:

#!/bin/sh
#Below is the output
echo "Foo bar"
#below is the return code
exit 2
#END

The above is a dummy plugin that would always show up as
CRITICAL.

-Jason Martin

> -----Original Message-----
> From: Robert Reeves 
> Sent: Tuesday, January 03, 2006 3:50 PM
> To: Robert Reeves; Subhendu Ghosh
> Cc: nagios-users at lists.sourceforge.net
> Subject: RE: [Nagios-users] Remotely Checking Windows: Mapped Network
> Drives
> 
> I got it working.
> 
> Add this to your nrpe.cfg file...
> command[check_nrpe_new_disk]=C:\WINNT\system32\cscript.exe /Nologo
> C:\nrpe\plugins\checkmappednetworkdrives.vbs $ARG1$ $ARG2$ $ARG3$
> 
> Here's checkmappednetworkdrives.vbs...
> 
> 'On Error Resume Next
> 
> DeviceName = WScript.Arguments.Item(0)
> 'Wscript.Echo "DeviceName=" & DeviceName WarningPercentage =
> WScript.Arguments.Item(1) 'Wscript.Echo "WarningPercentage=" &
> WarningPercentage CriticalPercentage = WScript.Arguments.Item(2)
> 'Wscript.Echo "CriticalPercentage=" & CriticalPercentage
> 
> strComputer = "."
> Set objWMIService = GetObject("winmgmts:" _
>     & "{impersonationLevel=impersonate}!\\" & strComputer &
> "\root\cimv2")
> 
> Set colItems = objWMIService.ExecQuery("Select * from
> Win32_MappedLogicalDisk WHERE DeviceID=""" & DeviceName & """")
> 
> For Each objItem in colItems
> 	PercentageFree = objItem.FreeSpace / objItem.Size
> 	PercentageFree = Int(PercentageFree * 100)
> 	
> 	If (PercentageFree <= Int(CriticalPercentage)) Then
> 		ReturnCode = "CRITICAL"
> 	ElseIf (PercentageFree <= Int(WarningPercentage)) Then
> 		ReturnCode = "WARNING"
> 	Else
> 		ReturnCode = "OK"
> 	End If
> 
> 	Wscript.Echo ReturnCode & " " & objItem.DeviceID & " -
> Percentage Free = " & PercentageFree & "% (" & objItem.FreeSpace & "/" &
> objItem.Size & ")"	
> Next
> 
> 
> -----Original Message-----
> From: nagios-users-admin at lists.sourceforge.net
> [mailto:nagios-users-admin at lists.sourceforge.net] On Behalf Of Robert
> Reeves
> Sent: Wednesday, December 21, 2005 10:39 AM
> To: Subhendu Ghosh
> Cc: nagios-users at lists.sourceforge.net
> Subject: RE: [Nagios-users] Remotely Checking Windows: Mapped Network
> Drives
> 
> All are WindowsXP. 
> 
> I'll look into WMI32_MappedLogicalDisk. Have you had success with that
> before?
> 
> Thanks!
> 
> Robert
> 
> -----Original Message-----
> From: nagios-users-admin at lists.sourceforge.net
> [mailto:nagios-users-admin at lists.sourceforge.net] On Behalf Of Subhendu
> Ghosh
> Sent: Wednesday, December 21, 2005 10:03 AM
> To: Robert Reeves
> Cc: nagios-users at lists.sourceforge.net
> Subject: Re: [Nagios-users] Remotely Checking Windows: Mapped Network
> Drives
> 
> On Wed, 21 Dec 2005, Robert Reeves wrote:
> 
> > I have several windows servers that use mapped network drives. At 
> > times, these drives become unavailable and halt services. I would like
> 
> > to be able to monitor these drives.
> >
> > I have both NRPE_NT and nsclient running on the Windows boxes. Both 
> > responses are not working for me:
> >
> > NRPE
> > Status: OK
> > Status Information: DEBUG : 12/21/05 08:59:15: GetDiskFreeSpaceEx() 
> > returned an error
> >
> > Nsclient:
> > Status: UNKNOWN
> > Status Information: Free disk space : Invalid drive
> >
> > I have attempted to run both services as the SYSTEM account and as a 
> > valid domain user. Both result in the same response.
> >
> > There is an earlier thread that suggests granting the SYSTEM user 
> > permissions to the share. However, due to some uniqueness with how we 
> > set up the mapped network drives, I am unable to change the 
> > permissions on the shares. There are from a Linux box running Samba.
> >
> > Does anybody have a solution for this? I simply need to make sure the 
> > drives are accessible from the Windows server, so I'm willing to go in
> 
> > a different location instead of checking free space left.
> >
> > Thanks,
> >
> > Robert
> >
> 
> server os - win2k or win2k3?
> 
> Have you tried using NRPE_NT with a script that uses the
> WMI32_MappedLogicalDisk to enumerate mapped disks?
> 
> 

-- 
Best way to dispose of the Borg: Give them Windows 3.1.
This message is PGP/MIME signed.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 211 bytes
Desc: not available
URL: <https://www.monitoring-lists.org/archive/users/attachments/20060103/80ed1f22/attachment.sig>


More information about the Users mailing list