NRPE Looping the Config files - Nagios Core 4.3.4

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
xinxolHH
Posts: 14
Joined: Mon Feb 18, 2019 4:47 am

NRPE Looping the Config files - Nagios Core 4.3.4

Post by xinxolHH »

Hello,

I am doing indirect checks with NRPE in diferent locations, and those checks/services are usually all the same in each and every location.
so for example for a PC at the location B, I have the following check, in this file the IPofServerB is entered manually, and for each file.
the question, how can I better define a custome variable or enviromental variable, so I can have the IP address of Server B (IPofServerB)
as variable, and then for each different location, B,C,D,.....etc. A unique file for the services defined for all location, and then only define the IP address of the remote server. As well as to pass the variable name either in the hostname or in the alias, so we know from looking at table, which PC and which location has a warning or critical response.


On the other hand the IP of MyPC is always the same defined as static internal IP address. (10.161.164.220)

Code: Select all

define host {
        use                             windows-server
        host_name                       MyPC_$NAMEofB
        alias                           PC_Office_§NAMEofB
        address                         10.161.164.220
        max_check_attempts              5
        check_command                   check_nrpe_ext!IPofSERVERB!'check_ok'
        notification_interval           10
        check_interval                  2
        retry_interval                  1
        max_check_attempts              3
        check_period                    workhours
        
}


define service {
        use                                  generic-service
        host_name                       MyPC_$NAMEofB
        service_description          CPU_Load
        check_command              check_nrpe_ext!IPofSERVERB!'check_cpu'!'-a show-all'
}




Any suggestion will be appreciated.

Best Regards,


X.
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: NRPE Looping the Config files - Nagios Core 4.3.4

Post by benjaminsmith »

Hi @xinxolHH,

In Nagios you can use user macros to define custom variables. For example, you can define a variable for the ip address of server B, and then pass this to the check command.

User macros can be defined in /usr/local/nagios/etc/resource.cfg and explained in the Nagios Core documentation:
How Macros Work

Please let me know if this answers your question or not.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
xinxolHH
Posts: 14
Joined: Mon Feb 18, 2019 4:47 am

Re: NRPE Looping the Config files - Nagios Core 4.3.4

Post by xinxolHH »

Hello Benjamin,

Thanks for the reply. I have for example defined in the resource.cfg file the $HOSTADDRESS,

like that in the resource.cfg file, lets asume now the IPofServerB, the remote Linux server at each different location is 172.168.1.2, and then a second server in another location C, with IP address 172.168.1.3 (IPofServerC)....so on, so 172.168.1.4...for ServerD,...etc

Code: Select all

$HOSTADDRESS$= 172.168.1.2,172.168.1.3,172.168.1.4
So in this case, the idea is to have a unique file for the host definition, and the services assigned for all the locations with indentical set-up

Code: Select all


define host {
        use                             windows-server
        host_name                       MyPC
        alias                           PC_Office
        address                         10.161.164.220
        max_check_attempts              5
        check_command                   check_nrpe_ext!$HOSTADDRESS$!'check_ok'
        notification_interval           10
        check_interval                  2
        retry_interval                  1
        max_check_attempts              3
        check_period                    workhours
        
}


define service {
        use                          generic-service
        host_name                     MyPC
        service_description          CPU_Load
        check_command              check_nrpe_ext!$HOSTADDRESS$!'check_cpu'!'-a show-all'
}

Is this the correct understanding, is this possible? and produce no error, but how do I know in which location the service is performed.
Or should I create separate files for each location, (wich is the thing I would like to avoid), as the number of location to be monitored will increase with time, and the configuration files will mostly be the same, just changing the IP address of the remote server for each location.

Thanks in advanced
X.
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: NRPE Looping the Config files - Nagios Core 4.3.4

Post by benjaminsmith »

Hello,

In Nagios all services are associated with a hosts, so you'll define you hosts objects for every device, but the use of templates can save time and help organize your configuration files.

If all of the services are identical, I would recommend using templates for those services, and then storing the services in a single file for their hosts. By doing so, you can use a find/replace to quickly change the host_name associated with the service ( see Nagios Core Object Definitions ) and other values would be inherited from a common service template for that check.

Lastly, usually check commands are stored in a separate configuration file, and will use the systems macros to pass the host address, paths or other arguments. For example:

Code: Select all

define command {
    command_name    check-host-alive-http
    command_line    $USER1$/check_http -H $HOSTADDRESS$
}
Let me know if that answers your question.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
xinxolHH
Posts: 14
Joined: Mon Feb 18, 2019 4:47 am

Re: NRPE Looping the Config files - Nagios Core 4.3.4

Post by xinxolHH »

Hello Benjamin

Thanks for the information, it is not exactly what I am looking, but yes using the templates in separate files would be of course easier.
I also found a way a creating the templates using the M4 tool in linux with the macros, based on the following blog from 2009,
https://administratosphere.wordpress.c ... -with-m4/
I also need to rename the services with a suffix or a varible for each location so I can indentify where the system is, but I wonder if there is a "better way" in Nagios.

my template m4 file looks like this one:

Code: Select all

define host {

        host_name                       PC2_$2
        alias                           PC2_$2 $1
        address                         10.161.164.220
        check_command                   check_nrpe_ext!$3!'check_ok'
        hostgroups                      $1
        check_interval                  10
        retry_interval                  1
        max_check_attempts              5
        check_period                    workhours
        process_perf_data               0
        retain_nonstatus_information    0
        notification_interval           30
        notification_period             workhours

        }
###############################################################################
# Services -  for Clients and Hosts
###############################################################################
define service {
        use                             generic-service
        hostgroup_name                  $1
        service_description             CPU_Load_$2
        check_command                   check_nrpe_ext!$3!'check_cpu'!'-a show-all'
}

define service {
        use                             generic-service
        hostgroup_name                  $1
        service_description             DriveC_$2
        check_command                   check_nrpe_ext!$3!'check_drivesize'!'-a drive=C:'
}

where:

Code: Select all

 $1 is the Location name used for the hostgroup definition
 $2 is the Alias or comon 4-Digit name for Description
 $3 is the IP address of Nagios Remote Server/Linux remote server installed on the remote Location

Thanks for the help
X.
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: NRPE Looping the Config files - Nagios Core 4.3.4

Post by benjaminsmith »

Hello @xinxolHH,
but I wonder if there is a "better way" in Nagios.
Other than using user defined macros or templates, there's not really another way to pre-define settings or variables for your configurations.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
xinxolHH
Posts: 14
Joined: Mon Feb 18, 2019 4:47 am

Re: NRPE Looping the Config files - Nagios Core 4.3.4

Post by xinxolHH »

Hello Benjamin,

thanks for the ideas and answers and support here. Yes I am using macros and templates and deploying the Nagios files with m4 too under Linux. It is good enough. We can close this threat.

Thanks and best regards
X.
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: NRPE Looping the Config files - Nagios Core 4.3.4

Post by benjaminsmith »

Hi X.
It is good enough. We can close this threat.
Closing thread.

Thank you for using the Nagios Support Forum.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked