Command HOST_NAME Macro

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
sistemasproadata
Posts: 12
Joined: Mon Jan 15, 2018 8:36 am

Command HOST_NAME Macro

Post 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
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Command HOST_NAME Macro

Post by npolovenko »

Hello, @sistemasproadata.
Can you show us how you defined the command veeam_estado?
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Command HOST_NAME Macro

Post 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
        }
Former Nagios employee
https://www.mcapra.com/
sistemasproadata
Posts: 12
Joined: Mon Jan 15, 2018 8:36 am

Re: Command HOST_NAME Macro

Post 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 -
sistemasproadata
Posts: 12
Joined: Mon Jan 15, 2018 8:36 am

Re: Command HOST_NAME Macro

Post 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
        }
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Command HOST_NAME Macro

Post 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.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
sistemasproadata
Posts: 12
Joined: Mon Jan 15, 2018 8:36 am

Re: Command HOST_NAME Macro

Post 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
                     }
}

npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Command HOST_NAME Macro

Post 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:

Code: Select all

passed argument: srvcon003
So the macro does work. Maybe the problem is that it splits the hostname and only uses the first part before the period?
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
sistemasproadata
Posts: 12
Joined: Mon Jan 15, 2018 8:36 am

Re: Command HOST_NAME Macro

Post 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
sistemasproadata
Posts: 12
Joined: Mon Jan 15, 2018 8:36 am

Re: Command HOST_NAME Macro

Post 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
Locked