Page 1 of 2
Command HOST_NAME Macro
Posted: Mon Jan 15, 2018 8:54 am
by sistemasproadata
Hi, i have this command defined :
$USER1$/check_nrpe -H 172.18.0.67 -t 30 -c veeam_estado -a $HOSTNAME$
the macro $HOSTNAME$ is not returning me the name defined on the host cfg:
define host {
host_name srvcon003.proa.com
use xiwizard_windowsserver_host
someone knows why?
Thanks
Re: Command HOST_NAME Macro
Posted: Mon Jan 15, 2018 2:29 pm
by npolovenko
Hello,
@sistemasproadata.
Can you show us how you defined the command
veeam_estado?
Re: Command HOST_NAME Macro
Posted: Mon Jan 15, 2018 4:10 pm
by mcapra
In addition to the NSClient/NRPE command definition, It might also be worthwhile to know which version of Nagios XI you are using as well as the NSClient/NRPE version.
I didn't have any issues passing
$HOSTNAME$ in a
command definition on Nagios Core 4.3.2 which makes me think this is an issue with the agent's setup:
Code: Select all
define host{
use linux-server
host_name PRODHERMES1
address 17.212.19.8
check_command check_ping!1000.0,50%!2000.0,80%
}
define service{
use elasticsearch-prod ; Name of service template to use
hostgroup_name HERMESPROD
service_description Hermes Front-end on 7777
check_command test_macros_host
}
define command{
command_name test_macros_host
command_line echo $HOSTNAME$ is the hostname && exit 0
}
Code: Select all
servicestatus {
host_name=PRODHERMES1
service_description=Hermes Front-end on 7777
check_command=test_macros_host
plugin_output=PRODHERMES1 is the hostname
}
Re: Command HOST_NAME Macro
Posted: Tue Jan 16, 2018 5:06 am
by sistemasproadata
npolovenko wrote:Hello,
@sistemasproadata.
Can you show us how you defined the command
veeam_estado?
[/settings/external scripts/scripts]
veeam_estado = cmd /c echo scripts\\veeam_estado.ps1 $ARG1$; exit($lastexitcode) | powershell.exe -command -
Re: Command HOST_NAME Macro
Posted: Tue Jan 16, 2018 5:10 am
by sistemasproadata
nagios:
Your Nagios XI installation is up to date.
Latest Available Version: 5.4.11
Installed Version: 5.4.11
Last Update Check: 16/01/2018 08:34:02
nrpe:
NRPE Plugin for Nagios
Copyright (c) 1999-2008 Ethan Galstad (
[email protected])
Version: 2.15
nsclient:
NRPE Plugin for Nagios
Copyright (c) 1999-2008 Ethan Galstad (
[email protected])
Version: 2.15
mcapra wrote:In addition to the NSClient/NRPE command definition, It might also be worthwhile to know which version of Nagios XI you are using as well as the NSClient/NRPE version.
I didn't have any issues passing
$HOSTNAME$ in a
command definition on Nagios Core 4.3.2 which makes me think this is an issue with the agent's setup:
Code: Select all
define host{
use linux-server
host_name PRODHERMES1
address 17.212.19.8
check_command check_ping!1000.0,50%!2000.0,80%
}
define service{
use elasticsearch-prod ; Name of service template to use
hostgroup_name HERMESPROD
service_description Hermes Front-end on 7777
check_command test_macros_host
}
define command{
command_name test_macros_host
command_line echo $HOSTNAME$ is the hostname && exit 0
}
Code: Select all
servicestatus {
host_name=PRODHERMES1
service_description=Hermes Front-end on 7777
check_command=test_macros_host
plugin_output=PRODHERMES1 is the hostname
}
Re: Command HOST_NAME Macro
Posted: Tue Jan 16, 2018 10:26 am
by npolovenko
@sistemasproadata, Your command definition seems right. Can you upload the veeam_estado.ps1 script here, or send it to me in a PM? That way I could actually test it on my system to see what's going on.
Re: Command HOST_NAME Macro
Posted: Wed Jan 17, 2018 3:10 am
by sistemasproadata
hi, is a simple code to check if one virtual machines is copied on the last veeam backup, the problem is not sending the name of the server as arg, is sending "$HOSTNAME$" as text
Code: Select all
asnp VeeamPSSnapin
$VMName = $args[0].Split(".")[0]
foreach($Job in (Get-VBRJob))
{
$Session = $Job.FindLastSession()
if(!$Session){continue;}
$Tasks = $Session.GetTaskSessions()
$returncode= 0
$estado= $Tasks | ?{$_.Name -eq $VMName} | %{$_.Status}
if ($estado -eq "Success")
{
$returncode= 0
write "$estado|$returncode"
exit $returncode
}
if ($estado -eq "Warning")
{
$returncode= 1
write "$estado|$returncode"
exit $returncode
}
}
Re: Command HOST_NAME Macro
Posted: Wed Jan 17, 2018 11:49 am
by npolovenko
@sistemasproadata, I did run a test. I added the command just like you have it.
Code: Select all
[/settings/external scripts/scripts]
veeam_estado = cmd /c echo scripts\\veeam_estado.ps1 $ARG1$; exit($lastexitcode) | powershell.exe -command -
I changed the Powershell script to this:
Code: Select all
$VMName = $args[0].Split(".")[0]
Write-Host "passed argument: $VMName "
Then I created a service that uses the following command:
Code: Select all
$USER1$/check_nrpe -H 192.168.3.231 -c veeam_estado -a $HOSTNAME$
I called the host: "srvcon003.proa.com"
Here's the output i'm getting:
So the macro does work. Maybe the problem is that it splits the hostname and only uses the first part before the period?
Re: Command HOST_NAME Macro
Posted: Mon Jan 22, 2018 5:08 am
by sistemasproadata
Hi, my problem is the macro $HOSTNAME$ is sending me the name of the nagios machine, not the hostname defined on the nagios conf for the host.
Regards
Re: Command HOST_NAME Macro
Posted: Mon Jan 22, 2018 5:18 am
by sistemasproadata
[
[email protected] ~]$ /usr/local/nagios/libexec/check_nrpe -H 172.18.0.67 -t 30 -c veeam_estado -a $HOSTNAME$
passed argument: srvmanmon002
srvmanmon002 is the hostname of nagios