Page 2 of 3

Re: Check Windows Process memory

Posted: Wed Jan 13, 2016 12:34 pm
by JohnFLi
Ok, I'm almost there.....

my powershell script is:

Code: Select all

param($warn, $crit)
$LastExitCode = 3
$Output1 = ""
$output = ""
$myW3WP = Get-Process w3wp |  Sort -Descending WS| select -first 1 | Measure-Object WS -Sum 
$myW3WP = $myW3WP.sum / 1mb

 
if ($myW3WP -gt $crit)
        {
            $LastExitCode = 2
            $output1 = "CRITICAL: Memory for W3WP has passed 1 gig $myW3WP"
            $output = $output1
            
            
        }
    elseif ($myW3WP -gt $warn)
        {
            $LastExitCode = 1
            $output1 = "WARN: Memory for W3WP is getting close to 1 gig $myW3WP"
            $output = $output1
            
            
        }
    else 
        {
            $LastExitCode = 0
         
           
        }


$output = $output1
Write-Host $output $LastExitCode 
$myW3WP = ""

from the CL on the Nagios server I enter:

Code: Select all

./check_nrpe -H g1vpfms02 -c check_w3wp -a 200 1000
The response (in the CL) is:

Code: Select all

WARN: Memory for W3WP is getting close to 1 gig 217.83203125 1
yet in XI, it returns this:

Code: Select all

Ok
Cannot convert value "$" to type "System.Double". Error: "Input string was not
in a correct format."

At C:\\scripts\\checkW3WP.ps1:9 char:5

+ if ($myW3WP -gt $crit)

+ ~~~~~~~~~~~~~~~~~

+ CategoryInfo : InvalidArgument: (:) [], RuntimeException

+ FullyQualifiedErrorId : InvalidCastFromStringToDoubleOrSingle

3
any ideas on that??

Also, what do I need to change so Nagios with also display warning or critical? even with this, it still shows Green

Re: Check Windows Process memory

Posted: Wed Jan 13, 2016 5:36 pm
by lmiltchev
This looks good. I would add the following line on the bottom of the script:

Code: Select all

echo $myW3WP
Place the script in the NSClient++ scripts directory, define the check in the "nsclient.ini" file, i.e.

Code: Select all

check_process_memory = cmd /c echo scripts\process_mem.ps1; exit $LastExitCode | powershell.exe -command -
and test it from the CLI on the Nagios XI server:

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H <client ip> -p 5666 -c check_process_memory
Edit: I didn't realize you made another post on the 2nd page. I was replying to the previous post - sorry about that! Give us some time to test this in house.

Re: Check Windows Process memory

Posted: Thu Jan 14, 2016 4:36 pm
by JohnFLi
any luck?

Re: Check Windows Process memory

Posted: Fri Jan 15, 2016 10:01 am
by lmiltchev
OK. Try the following:

1. Change your script to look like this:

Code: Select all

param($warn, $crit)
    $LastExitCode = 3
    $output = ""
    $myW3WP = Get-Process w3wp |  Sort -Descending WS| select -first 1 | Measure-Object WS -Sum
    $myW3WP = $myW3WP.sum / 1mb


    if ($myW3WP -gt $crit)
            {
                $output = "CRITICAL: Memory for W3WP has passed 1 gig $myW3WP"
                $LastExitCode = 2
			}	
        elseif ($myW3WP -gt $warn)
            {
                $output = "WARN: Memory for W3WP is getting close to 1 gig $myW3WP"
                $LastExitCode = 1
            }
        else
            {
                $output = "OK: Everything seems to be fine $myW3WP"
				$LastExitCode = 0
            }

	Write-Host $output
	exit $LastExitCode
2. Define your command in the nsclient.ini as this:

Code: Select all

check_w3wp = cmd /c echo scripts\check_w3wp.ps1 $ARG1$; exit $LastExitCode | powershell.exe -command -
3. Test your check by running the following command on the Nagios XI box:

Code: Select all

./check_nrpe -H g1vpfms02 -c check_w3wp -a '200 1000'
Let me know if this helped. I am pretty sure this can be improved but this should at least get you started.

Re: Check Windows Process memory

Posted: Fri Jan 15, 2016 11:36 am
by JohnFLi
I copy and pasted the re-write of the powershell you supplied

in the .ini file

Code: Select all

[/settings/external scripts/scripts]
check_w3wp=cmd /c echo C:\scripts\checkW3WP.ps1 "$ARG1$"; exit $LastExitCode | powershell.exe -command -
from CLI

Code: Select all

 ./check_nrpe -H g1vpfms02 -c check_w3wp -a '200 1000'
output:

Code: Select all

CRITICAL: Memory for W3WP has passed 1 gig 240.82421875
so now it thinks 240 > 1000

XI reports the same, but at least it is reporting instead of erroring.


just did a test...when passing the variable to the powershell, its passing 200 1000 into the $warn and nothing into the $crit

Re: Check Windows Process memory

Posted: Fri Jan 15, 2016 1:54 pm
by lmiltchev
H-m-m, it works for me as far as I can tell:

Code: Select all

[root@localhost libexec]# ./check_nrpe -H x.x.x.x -c check_w3wp -a '500 1000'
OK: Everything seems to be fine 436.9609375
[root@localhost libexec]# ./check_nrpe -H x.x.x.x -c check_w3wp -a '200 1000'
WARN: Memory for W3WP is getting close to 1 gig 449.60546875
[root@localhost libexec]# ./check_nrpe -H x.x.x.x -c check_w3wp -a '200 300'
CRITICAL: Memory for W3WP has passed 1 gig 448.64453125
Try removing the double quotes from around your arg:

Code: Select all

check_w3wp=cmd /c echo C:\scripts\checkW3WP.ps1 $ARG1$; exit $LastExitCode | powershell.exe -command -
and restart NSClient++ service. Did this help?

Re: Check Windows Process memory

Posted: Fri Jan 15, 2016 4:05 pm
by JohnFLi
yeah, it's weird..... it's happy at the CLI,
but XI, and core it isn't working right

in CLI

Code: Select all

./check_nrpe -H g1vpfms02 -c check_w3wp -a '200 1000'
OK: Everything seems to be fine 169.0625
in XI:

Code: Select all

Current Status:	  CRITICAL   (for 0d 0h 5m 24s)
Status Information:	CRITICAL: Memory for W3WP has passed 1 gig 169.03515625

Re: Check Windows Process memory

Posted: Sun Jan 17, 2016 11:04 pm
by Box293
Can you please post your Nagios XI service definition. In CCM > Monitoring > Services click the icon that looks like a disk and you will get it's text config.

Re: Check Windows Process memory

Posted: Mon Jan 18, 2016 11:10 am
by JohnFLi

Code: Select all

define service {
	host_name			G1VPFMS02
	service_description		W3WP Memory
	check_command			check_nrpe!check_w3wp!200 1000!!!!!!
	max_check_attempts		5
	check_interval			5
	retry_interval			1
	check_period			xi_timeperiod_24x7
	notification_interval		5
	first_notification_delay	0
	notification_period		xi_timeperiod_24x7
	notification_options		w,c,u,
	contacts			My Name
	register			1
	}	
at CLI

Code: Select all

./check_nrpe -H g1vpfms02 -c check_w3wp -a '200 1000'
OK: Everything seems to be fine 194.9296875
XI display:

Code: Select all

G1VPFMS02View service status details for this host	W3WP MemoryNotifications are disabled for this service	Critical	2d 18h 12m 19s	5/5	01/18/2016 08:08:29	CRITICAL: Memory for W3WP has passed 1 gig 194.94140625

Re: Check Windows Process memory

Posted: Mon Jan 18, 2016 1:11 pm
by tgriep
Edit the W3WP Memory service on your XI server
Change your $ARG2$ from

Code: Select all

200 1000
to

Code: Select all

-a '200 1000'
Save it out and apply the config and let us know if this fixes it for you.
The default $ARG2$ for check_nrpe is blank so you you need to fill in the full command line arguments for $ARG2$.