I wrote a powershell script for windows failover cluster monitoring. On which i have a scenario where i need to check for a running service on all the cluster nodes.
when running my script from Nagios, the script only fetches the service on the current node where the check_ncpa command runs, and it fails to get details on other clusternode
i am using "Get-Service -ComputerName" to do this and it fails running from Nagios. Should i need to do a enter-PSsession to do this ? why my local account could connect remotly but not when called from nagios?
My Powershell function look like this
Code: Select all
function GetServiceStatus {
param (
$servicename #"Microsoft iSCSI Initiator Service" , "NCPA Listener - ncpalistener"
)
try {
$servicename = $servicename -split "," -replace('"',"") | % { $_.Trim() } | where { $_ } | select -Unique
if ($servicename.Count -gt 0) {
foreach ($node in $ownernode.Keys) {
$servicename | % { If ($(Get-Service -ComputerName $node -Name $_ ).Status -eq "Running")
{ $running_services[$_] += ",$node" } }
}
}
}
catch {
Write-Host "UnKnown: Something went wrong in GetServiceStatus"
$Global:returncode = 3
}
}.\winClusterHealth.ps1 -failover_retention 11 -services_onallnodes "Microsoft iSCSI Initiator Service,NCPA Listener - ncpalistener"
Microsoft iSCSI Initiator Service {clusternode1, clusternode2}
NCPA Listener - ncpalistener {clusternode1, clusternode2}
when executing the script locally as my user, i can get the service running on my local machine and on all the cluster nodes,
but when i use check_ncpa.py to call my script as below from my nagios server
Code: Select all
./check_ncpa.py -H 'clusternode1' -t 'token' -P 5693 -M 'plugins/winClusterHealth.ps1' -a '-services_onallnodes "Microsoft iSCSI Initiator Service,NCPA Listener - ncpalistener"' [Running from nagios it only fetches the service from the clusternode1]
./check_ncpa.py -H ctlrck-vdwn001.wsgc.com -t 'g8fwRYLrbh6Zf' -P 5693 -M 'plugins/winClusterHealth.ps1' -a '-failover_retention 1400 -services_onallnodes "Microsoft iSCSI Initiator Service,NCPA Listener - ncpalistener"'
Microsoft iSCSI Initiator Service clusternode1
NCPA Listener - ncpalistener clusternode1
Get-Service : Cannot find any service with service name 'Microsoft iSCSI
Initiator Service'.
At C:\Program Files (x86)\Nagios\NCPA\plugins\winClusterHealth.ps1:77 char:42
+ $servicename | % { If ($(Get-Service -ComputerName $node
-Name $ ...
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft iSCSI Initiator Servi
ce:String) [Get-Service], ServiceCommandException
+ FullyQualifiedErrorId : NoServiceFoundForGivenName,Microsoft.PowerShell.
Commands.GetServiceCommand
Get-Service : Cannot find any service with service name 'NCPA Listener -
ncpalistener'.
At C:\Program Files (x86)\Nagios\NCPA\plugins\winClusterHealth.ps1:77 char:42
+ $servicename | % { If ($(Get-Service -ComputerName $node
-Name $ ...
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (NCPA Listener - ncpalistener:St
ring) [Get-Service], ServiceCommandException
+ FullyQualifiedErrorId : NoServiceFoundForGivenName,Microsoft.PowerShell.
Commands.GetServiceCommand