Check_nrpe + Powershell

An open discussion forum for obtaining help with Nagios Core. Nagios Core users of all experience levels are welcome here. Subforum have been created for the discussion of Nagios Core and Nagios Plugin development.

NOTE: The SourceForge.net mailing lists have been deprecated in favor of this forum in order to expedite support and provide additional features not available on the old mailing list.

Check_nrpe + Powershell

Postby joaase » Mon Mar 20, 2017 7:38 am

Hi.
Trying to create a new check too look when last windows update was install. i whant this check to run from one server and in my powershell script use New-PSSession to run script into Another server.
my powershell script look like this.

param (
[string] $computername
)

$password = ConvertTo-SecureString "password" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ("username",$password )
$s = New-PSSession -ComputerName $computername -Credential $cred

$result = invoke-command -session $s -scriptblock {Get-ItemProperty -path "HKLM:\Software\microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\Results\Install" -Name LastSuccessTime | select -Property LastSuccessTime}

Write-host = $result | select -Property LastSuccessTime

if i run script line by line its work perfect and give me correct value back
if i try to run script .\WindowsUpdate.ps1 "computername" is work perfect and give me correct value back

My op5.ini file look like this: check_Windowsupdate = cmd /c echo scripts\custom\WindowsUpdate.ps1 "$ARG1$" ; exit($lastexitcode) | powershell.exe -command -

MY check in OP5 look like this: $USER1$/check_nrpe -s -H $HOSTADDRESS$ -c check_Windowsupdate

my op5.ini file i have put this in under [/settings/external scripts/scripts]

when i try this check in op5 i get an error:

New-PSSession : One or more computer names are not valid. If you are trying to
pass a URI, use the -ConnectionUri parameter, or pass URI objects instead of st
rings.
At C:Program FilesNSClient++scriptscustomWindowsUpdate.ps1:9 char:6
+ $s = New-PSSession -ComputerName $computername -Credential $cred
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (System.String[]:String[]) [New
-PSSession], ArgumentException
+ FullyQualifiedErrorId : PSSessionInvalidComputerName,Microsoft.PowerShel
l.Commands.NewPSSessionCommand

Invoke-Command : Cannot validate argument on parameter 'Session'. The argument
is null or empty. Provide an argument that is not null or empty, and then try t
he command again.
At C:Program FilesNSClient++scriptscustomWindowsUpdate.ps1:11 char:35
+ $result = invoke-command -session $s -scriptblock {Get-ItemProperty -path "HK
LM: ...
+ ~~
+ CategoryInfo

Please can someone help me to understand what the problems is?

Best regard
Joakim
joaase
 
Posts: 9
Joined: Fri Apr 17, 2015 7:26 am

Re: Check_nrpe + Powershell

Postby mcapra » Mon Mar 20, 2017 12:24 pm

joaase wrote:My op5.ini file look like this: check_Windowsupdate = cmd /c echo scripts\custom\WindowsUpdate.ps1 "$ARG1$" ; exit($lastexitcode) | powershell.exe -command -

MY check in OP5 look like this: $USER1$/check_nrpe -s -H $HOSTADDRESS$ -c check_Windowsupdate

my op5.ini file i have put this in under [/settings/external scripts/scripts]

when i try this check in op5 i get an error:


This sounds like an op5 issue more than a Nagios Core issue. I would recommend seeking assistance through that community.
Former Nagios employee - https://github.com/mcapra/
User avatar
mcapra
 
Posts: 2451
Joined: Thu May 05, 2016 3:54 pm


Return to Nagios Core

Who is online

Users browsing this forum: No registered users and 19 guests