This support forum board is for support questions relating to
Nagios XI , our flagship commercial network monitoring solution.
InesDiLorenzo89
Posts: 14 Joined: Mon Jun 06, 2016 9:36 am
Post
by InesDiLorenzo89 » Wed Jun 08, 2016 10:19 am
Good morning,
I have inserted a script on a windows machine to make check_f5 .
My code is this:
Code: Select all
# Credenziali F5
$user = "*****"
$pw = "*****"
$hostname = "******" # PROD
$poolNameLike = "*New-Scheduall-Prod*" # PROD
$StatoGREEN = "AVAILABILITY_STATUS_GREEN"
$StatoBLU = "AVAILABILITY_STATUS_BLUE"
$availabilityLike = "*is available*"
$addr="*********"
Try {
Add-PSSnapin iControlSnapin
$success=Initialize-F5.iControl -HostName $hostname -Username $user -Password $pw
Clear-Host $success
$ic = Get-F5.iControl
# Recupera la lista dei pool
$pools = $ic.LocalLBPool.get_list()
$a=0
# Cicla sulla lista dei pool, skippando tutti quelli non "New-Scheduall-Prod*"
foreach($pool in $pools) {
if($pool -notlike $poolNameLike) { continue }
# Lista dei membri con relative informazioni
$members = Get-F5.LTMPoolMember -Pool $pool
foreach($member in $members) {
if($member.Address -like $addr) {continue}
$port = $members.Port
$name = $members.Name
$availability = $members.Availability
$enable = $members.enabled
$status = $members.Status
if(($member.Availability -eq $StatoGREEN) -or ($member.Availability -eq $StatoBLU)) {
Write-Host "Service Status" $pool " is ok => " $member.Address #OK
}
else
{
$a++;
Write-Host "Service Status" $pool " is ko => " $member.Address #KO
}
}
}
If ($a -eq 0) {
$exitcode= 0
Write-Host "No poolmember down"
Exit $exitcode
}
else {
$exitcode= 2
Write-Host "Poolmember down"
Exit $exitcode
}
} Catch [Exception] {
$exitcode=1
$err = $_.Exception.Message
$err
Exit $a
}
The command sending is this:
Code: Select all
$USER1$/check_nrpe -H $HOSTADDRESS$ -t 30 -c $ARG1$ $ARG2$
Where $ARG1 check_f5 and $ARG2$ -a 1 2
Unfortunately, however, it does not respect the constraints placed by me or does not go critical and warning .
Thanks so much.
rkennedy
Posts: 6579 Joined: Mon Oct 05, 2015 11:45 am
Post
by rkennedy » Wed Jun 08, 2016 10:30 am
Try setting $ARG2$ to "-a 1 2" rather then just -a 1 2, this may make a difference.
Former Nagios Employee
InesDiLorenzo89
Posts: 14 Joined: Mon Jun 06, 2016 9:36 am
Post
by InesDiLorenzo89 » Thu Jun 09, 2016 2:59 am
I tried to work on the $ a as the output as numeric but nothing this is the result :
Code: Select all
COMMAND : / usr / local / nagios / libexec / check_nrpe W12PUBPRAS01.sedi.publitalia.dom -H -t 30 -c check_f5 " -a 1 2 "
OUTPUT : 3
Code: Select all
COMMAND: /usr/local/nagios/libexec/check_nrpe -H W12PUBPRAS01.sedi.publitalia.dom -t 30 -c check_f5 -a 1 2
OUTPUT: 3
Nothing changes .
I enclose also the modified code .
The affected part is this:
Code: Select all
Try {
Add-PSSnapin iControlSnapin
$success=Initialize-F5.iControl -HostName $hostname -Username $user -Password $pw
Clear-Host $success
$ic = Get-F5.iControl
# Recupera la lista dei pool
$pools = $ic.LocalLBPool.get_list()
$a=0
# Cicla sulla lista dei pool, skippando tutti quelli non "New-Scheduall-Prod*"
foreach($pool in $pools) {
if($pool -notlike $poolNameLike) { continue }
# Lista dei membri con relative informazioni
$members = Get-F5.LTMPoolMember -Pool $pool
foreach($member in $members) {
#if($member.Address -like $addr) {continue}
$port = $members.Port
$name = $members.Name
$availability = $members.Availability
$enable = $members.enabled
$status = $members.Status
if(($member.Availability -eq $StatoGREEN) -or ($member.Availability -eq $StatoBLU)) {
#Write-Host "Service Status" $pool " is ok => " $member.Address #OK
}
else
{
$a++;
#Write-Host "Service Status" $pool " is ko => " $member.Address #KO
}
}
}
If ($a -eq 0) {
$exitcode= 0
Write-host $a
#Write-Host "No poolmember down"
#write-host "The number of user connected is :" $a "|'Num_User_RDP'="$a
Exit $exitcode
}
else {
$exitcode= 2
Write-host $a
#Write-Host "Poolmember down"
# write-host "The number of user connected is :" $a "|'Num_User_RDP'="$a
Exit $exitcode
}
} Catch [Exception] {
$exitcode=1
$err = $_.Exception.Message
$err
Exit $a
}
InesDiLorenzo89
Posts: 14 Joined: Mon Jun 06, 2016 9:36 am
Post
by InesDiLorenzo89 » Thu Jun 09, 2016 3:38 am
I am reading other posts I tried to change the command to launch the powershell and even powershell code.
FILE NSC.INI
Code: Select all
check_f5=cmd /c echo scripts\check_f5.ps1; exit($exitcode) | powershell.exe -Version 2 -command -
A PART OF POWERSHELL
Code: Select all
If ($a -eq 0) {
$exitcode= 0
Write-Host $exitcode
}
else {
$exitcode= 2
Write-Host $exitcode
}
But nothing change! Any ideas?
rkennedy
Posts: 6579 Joined: Mon Oct 05, 2015 11:45 am
Post
by rkennedy » Thu Jun 09, 2016 10:26 am
Maybe I'm missing it, but where are you taking in the inputs for your powershell script? I don't see a place where you are defining what $1 and $2 will represent. You're setting $a to 0.
Former Nagios Employee