Powershell script result is not completed display on nagios

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
kunalv30
Posts: 6
Joined: Thu Oct 26, 2017 1:29 am

Powershell script result is not completed display on nagios

Post by kunalv30 »

Code: Select all

clear-host

Add-PSSnapin -Name sqlserverprovidersnapin100 -ErrorAction SilentlyContinue
Add-PSSnapin -Name sqlservercmdletsnapin100 -ErrorAction SilentlyContinue
try
{

$DBservers = ('ServerFQDN')
#Clear-Variable -name Alert -Scope Global
#$DBservers = ('ServerFQDN','ServerFQDN\SQL2017')
foreach ($DBServer in $DBservers)
{

$QueryText1 = "select name from sys.databases where state_desc = 'online'"

$DBname = Invoke-SQLCMD $QueryText1 -ServerInstance $DBServer
if ($DBname -eq $null)
{
$QueryText4 = "select '$DBServer' as SQLInstance, name as DB_name, state_desc from sys.databases where state_desc <> 'online' and state_desc <> 'RESTORING' "
$DB = Invoke-SQLCMD $QueryText4 -ServerInstance $DBServer

if ($DB.name -eq $null)
{

}
else
{
$R3 = "Issue found, below are the details" 
Write-Host "Issue found, below are the details" 
$DB | Select * -ExcludeProperty RowError, RowState, Table, ItemArray, HasErrors | Format-Table | Out-File $output -append
$Alert  = '1'
}

}
else
{
$databases = $DBname.Name
$R3 = "Issue found, below are the details" 
foreach ($database in $databases)
{
$QueryText2 = "select '$DBServer' as SQLInstance, name as DB_name, state_desc from sys.databases where state_desc = 'online' and  name = '$database' "

$Result = Invoke-SQLCMD $QueryText2 -ServerInstance $DBServer 

If ($Result -eq $null) 
{
exit 3
}
Else
{

$Result | Select * -ExcludeProperty RowError, RowState, Table, ItemArray, HasErrors 
$Result
#| Out-File -FilePath $output -append

#| Format-Table 
$Alert  = '1'
}
}

}
}
If ($Alert -eq '1')
{
$R2 = "Problem occured" 
exit 2
}
else
{

$R4 = "No Issue:All Databases Are Online" 
exit 0
}
}
catch
{
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
Write-Host "Error:$ErrorMessage $FailedItem" 

break
}
Hello Folks,
I'm struggling to print the complete result of powershell output on nagios, i made a powershell script to show the databases status but result displayed on nagios of only 13 lines, actually result have 21 lines.
Note: I have already set the timeout of 180 sec on both nsclinet.ini and check_nrpe side.
command alias:
check_db_status = cmd //T:180 /c echo scripts\DB_Status.ps1; exit $LastExitCode | powershell.exe -command -

Powershell script as shared below, Please suggest
User avatar
lmiltchev
Former Nagios Staff
Posts: 13587
Joined: Mon May 23, 2011 12:15 pm

Re: Powershell script result is not completed display on nag

Post by lmiltchev »

How many characters total are shown in the output? Perhaps you would need to update the db so that it could store more information. See our KB article on the topic below:

https://support.nagios.com/kb/article/n ... s-478.html
Be sure to check out our Knowledgebase for helpful articles and solutions!
kunalv30
Posts: 6
Joined: Thu Oct 26, 2017 1:29 am

Re: Powershell script result is not completed display on nag

Post by kunalv30 »

@lmiltchev;

I have applied the changes which you have shared and same has been affected too, but i'm getting the same result. No improvement.
Changes :-
Before Database update:-
field,type
output;varchar(255)
long_output;varchar(8192)
perfdata;varchar(255)

After:-
field,type
output; mediumtext
long_output; text
perfdata;text
User avatar
lmiltchev
Former Nagios Staff
Posts: 13587
Joined: Mon May 23, 2011 12:15 pm

Re: Powershell script result is not completed display on nag

Post by lmiltchev »

When you said:
...but result displayed on nagios of only 13 lines, actually result have 21 lines.
you meant the output you see under the "Service Status Detail", correct? Can you show us a screenshot?

Do you see all 21 lines, when you run the check from the command line?

Example:

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H <ip address> -t 60 -c check_db_status
Be sure to check out our Knowledgebase for helpful articles and solutions!
kunalv30
Posts: 6
Joined: Thu Oct 26, 2017 1:29 am

Re: Powershell script result is not completed display on nag

Post by kunalv30 »

Powershellresult.PNG
CLIresult.PNG
Hello lmiltchev,

I'm still trying on command line and once it'll show the completed output, i'll go on GUI. Facing issue at Command line.
PFA both the screenshots, 1. Command Line 2. Windows server Powershell script output.
You do not have the required permissions to view the files attached to this post.
User avatar
lmiltchev
Former Nagios Staff
Posts: 13587
Joined: Mon May 23, 2011 12:15 pm

Re: Powershell script result is not completed display on nag

Post by lmiltchev »

Try the following:

1. Modify your nsclient.ini file by setting the "payload length" value under the [/settings/default] and [/settings/NRPE/client/targets/default] sections to 8192.

Code: Select all

payload length = 8192
Restart the nsclient++ service, so that changes can take effect.

2. Test your check again from the CLI on the Nagios XI server by using the "-P" flag (--payload-size=SIZE).

Example:

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H <ip address> -t 180 -P 8192 -c check_db_status
Did you get larger output this time?
Be sure to check out our Knowledgebase for helpful articles and solutions!
kunalv30
Posts: 6
Joined: Thu Oct 26, 2017 1:29 am

Re: Powershell script result is not completed display on nag

Post by kunalv30 »

Hello lmiltchev,

I have done the following changes, but no luck.
Output which i gets, attachments for reference
You do not have the required permissions to view the files attached to this post.
User avatar
lmiltchev
Former Nagios Staff
Posts: 13587
Joined: Mon May 23, 2011 12:15 pm

Re: Powershell script result is not completed display on nag

Post by lmiltchev »

Can you post your nsclient.ini file on the forum? Obfuscate sensitive info. Thanks!
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked