NRPE + Powershell script Not Graphing

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
alsoszaa
Posts: 33
Joined: Fri Sep 21, 2018 10:52 am

NRPE + Powershell script Not Graphing

Post by alsoszaa »

I am using NRPE with a custom PowerShell script which works to provide the VMWare datastore percent free to a given datastore provided in in an argument within NagiosXI. However, I am not sure how to go about getting the percent free number to be graphed. I am 99% positive our Nagios uses HighCharts. I just need to know what I need to do in either the PowerShell script or the arguments within the nagios service I configured. Below are both provided so you can assist me. Please let me know if I am missing anything for you to assist. This works to give me the monitoring I need, but it does not provide me any graphs of historical reference. Graphing is what I need now.

PowerShell Script:

Code: Select all

$DAST = $args[0]

## BEGIN Global variables ##
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false | Out-Null
## Reset Status and Description
$NagiosStatus = "0"
$NagiosDescription = ""
$datum=Get-date -Format 'MM-dd-yyyy hh:mm'

## END Global Variables ##

Import-Module DJATools -DisableNameChecking

Connect-vSphere 

## Define the datastores to watch

$datastore = get-datastore | Where-Object {$_.name -like $DAST} 

## Add percent free and date to arrays
$datastore | ForEach-Object{
    $_ | Add-Member -MemberType NoteProperty -Name "SampleDate" -Value $datum
    $PctMath =($_.FreeSpaceGB / $_.CapacityGB *100)
    $PctFree=("{0:f2}" -f $PctMath)
    $_ | Add-Member -MemberType NoteProperty -Name "PercentFree" -Value $PctFree
}

Disconnect-VIServer -Confirm:$false

try{
    $datastorename = $datastore | select-object -ExpandProperty Name
	$datastoresize = $datastore | Select-Object  -ExpandProperty PercentFree
	$comment = "% free space"
	
    if ($NagiosDescription -ne "") {
	    ## Format the output for Nagios
		$NagiosDescription = "" 
    }
	if ($datastoresize -lt 15) {
	    if ($datastoresize -lt 10) {
	    ## Status Critical when Less than 10% free (more than 90% used)
		$NagiosDescription = $NagiosDescription + $datastorename + " has " + $datastoresize + $comment
		## Set the status to Critical.
		$NagiosStatus = "2"
        Write-Host "CRITICAL: $NagiosDescription"
	    }
		else {
	        ## Status Warning when less than 15% free (more than 85% used)
            $NagiosDescription = $NagiosDescription + $datastorename + " has " + $datastoresize + $comment
			## Set the status to Warning.
			$NagiosStatus = "1"
            Write-Host "Warning: $NagiosDescription"			
		}
	}
	if ($datastoresize -ge 15) {
	    ## Status okay when greater than or equal to 15% free (less than or equal to 85% used)
	    $NagiosDescription = $NagiosDescription + $datastorename + " has " + $datastoresize + $comment
		## Set the status to Okay.
		$NagiosStatus = "0"
        Write-Host "OK: $NagiosDescription"
	}	
}
catch{ 
    $ErrorMessage = $_.Exception.Message
    $FailedItem = $_.Exception.ItemName
    $UnknownState= "Yes"
    Write-Output "FAILED ITEM: '$FailedItem' ERROR MESSAGE: '$ErrorMessage'"
    $NagiosStatus = "3"
}

## Exit script and send status to Nagios
exit $NagiosStatus
Nagios Command:

Code: Select all

$USER1$/check_nrpe -H $HOSTADDRESS$ -t 30 -c $ARG1$ $ARG2$
Nagios Arguments:

Code: Select all

$ARG1$: PSCheckDataStore
$ARG2$: -a "VMW_CMSAN_CM1_UTD202 (P123) VMFS6"
nsclient.ini (under [/settings/external scripts]):

Code: Select all

PSCheckDataStore = cmd /c echo scripts\\DataStoreNagiosCheck.ps1 "$ARGS";  exit($lastexitcode) | powershell.exe -command -
User avatar
mbellerue
Posts: 1403
Joined: Fri Jul 12, 2019 11:10 am

Re: NRPE + Powershell script Not Graphing

Post by mbellerue »

Have you seen this document on performance data?
https://assets.nagios.com/downloads/nag ... fdata.html

The document is for Nagios Core, but it applies to XI. The output of your plugin should have the normal human readable message, followed by a | and then the performance data information.

Once you have that, you can start collecting and graphing the performance data.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
alsoszaa
Posts: 33
Joined: Fri Sep 21, 2018 10:52 am

Re: NRPE + Powershell script Not Graphing

Post by alsoszaa »

Awesome! I added the pipe followed by the variable info to the Write-Host line and now I see the graph! I did this to OK, Warn, and Critical.

Code: Select all

Write-Host "OK: $NagiosDescription | PercentFree=$datastoresize"
Thank you so much for your help!
User avatar
mbellerue
Posts: 1403
Joined: Fri Jul 12, 2019 11:10 am

Re: NRPE + Powershell script Not Graphing

Post by mbellerue »

You're welcome! I'll go ahead and close this thread. Feel free to open a new one if you encounter any trouble.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked