Model After

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
jkinning
Posts: 747
Joined: Wed Oct 09, 2013 2:54 pm

Model After

Post by jkinning »

I have created a host which has all the "base" checks we are looking for and the desired notification time and escalations. I am planning on using the Bulk Host Cloning and Import Monitoring Wizard to migrate all our hosts from Nagios Core to Nagios XI with these new values. Question is going forward is there a way to create new hosts going forward using this same "template"? And is there a way I can create a host template that doesn't really do any monitoring or notification but is simply there for when new hosts need to be added? I'll be having some sysadmins add new hosts and it would be nice if I could have them just use the Bulk Host Cloning and Import Monitoring Wizard and select a host called something like windows_nonprod_template which will have all the "base"checks and things included. Prevent anyone from selecting a machine that may be different and avoid any confusion. I tried to rename a host but then I need to disable all the notifications because I am getting notified. When I disable it I don't see it in the drop down.

I am just looking for a template that going forward new hosts can get cloned and imported against based on being a production server or non production server.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Model After

Post by lmiltchev »

With the "Bulk Host Cloning and Import Monitoring Wizard" you can only use an actual, active host as a "template". You cannot use a real host template.
If this particular host is set exactly as you want it, you can clone it as many time as you want in the future.
As an alternative, you can try adding hosts/services from the CLI. Please, review our "Automated Host Management In Nagios XI" document here:

http://assets.nagios.com/downloads/nagi ... gement.pdf
Be sure to check out our Knowledgebase for helpful articles and solutions!
jkinning
Posts: 747
Joined: Wed Oct 09, 2013 2:54 pm

Re: Model After

Post by jkinning »

Ok, I tested this out and it appears to work. Has anyone created a script or anyone have a script, prevent me from reinventing the wheel, that can take an inputted value for host_name, alias, display_name, address, etc?

What would be really cool if I could present a web page for someone to access and key in those fields and then those fields fill in the cfg file and runs the reconfigure_nagios.sh script.

How are others using Nagios XI in this capacity? Meaning auto provisioning or automatically having hosts and base services checked? We are not using puppet or chef; however, Ansible has been mentioned but currently not using anything.
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Model After

Post by sreinhardt »

Honestly outside of nagiosql or our CCM, I don't know of anything you would reference as giving a few fields of information and it would create the rest of the configs. This would be really cool though, and I think you could probably accomplish about the same goals through templating and groups, but it might be a bit more difficult than a basic script to handle it. Most of the time we deal with adding\removing things automatically, it's usually through the backend api calls, or directly through the normal import chain after modifying a base config.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
jkinning
Posts: 747
Joined: Wed Oct 09, 2013 2:54 pm

Re: Model After

Post by jkinning »

I was trying to find some information about the backend API so maybe someone smarter than me could work this. In short, I am just trying to provide an easy way for other users to add hosts to the Nagios XI system or automate it so when a Server Request form gets filled out the basic checks with the define contacts and check intervals are in place and these systems monitored.

Google has not been very kind when I have searched to see how others may be accomplishing this.
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Model After

Post by abrist »

The real issue with this request is that most "easy" ways will write out to files in "static". To actually write those checks to the db will be much more difficult. Is the static directory an option? Or do you want these configs to exist the nagiosql db so they are accessible from the ccm?
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
mp4783
Posts: 116
Joined: Wed May 14, 2014 11:11 am

Re: Model After

Post by mp4783 »

I've done a lot of work recently with this. I'm confident in saying that the only way to achieve configuration changes via some form of external automation is to manipulate the relevant configuration files and then execute the Nagios reconfiguration script.
User avatar
mikew
Posts: 243
Joined: Sun Feb 05, 2012 7:05 pm

Re: Model After

Post by mikew »

This topic has been one I have spent a lot of time with as I work with a lot of very large installs. I gave a presentation which provides the outline of how to build this out:

http://www.slideshare.net/nagiosinc/nag ... s-40687039

The key to Rapid Deployment is to pull the configs out of Nagios, manipulate them and then return them into Nagios. In the Advanced Nagios class we use this script to implment 100 new servers with all of the appropriate services in less than 30 seconds. Currently I am developing scripts that will import all services for specific host types thus allowing you to build out an entire network infrastructure in 10 minutes based on groups of host types (Windows,Exchange,SQL,DNS,Linux,router,switches,etc).

I am working with Nagios to provide a database of Rapid Deployment scripts that should be available late this Spring. Currently the only way to get access to the scripts is to take the Advanced Nagios Class.
Mike Weber

Nagios Training/Consulting
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Re: Model After

Post by WillemDH »

Well I think Nagios XI host automatistion is actually a lot less hard then it seems. When you use host and service templates and use consistent naming conventions for all, it goes quite easy. You just use some template config file and do variable substitution on everything that needs to be changed. For example take this bas template config file for a Windowss server:

Code: Select all

define host {
        host_name                       ${Hostname}
        use                             dig_windows_server_prio${Prio}
        alias                           ${Hostname}
        address                         ${Ip}
        hostgroups                      +all_srv_inf_vir_${Infra},all_srv_loc_${Loc},all_srv_os_windows_${Os},all_srv_rol_${Role}
        check_period                    xi_timeperiod_24x7
        contacts                        +nagiosadmin
        contact_groups                  +xi_dig_dummy_contact_group
        notification_period             xi_timeperiod_24x7
        register                        1
        }

define service {
        host_name                       ${Hostname}
        service_description             DRV_C_Load
        use                             dig_srv_win_drv_c_load_prio2
        servicegroups                   +all_svc_dummy_servicegroup
        check_period                    xi_timeperiod_24x7
        notification_period             xi_timeperiod_24x7
        contacts                        +nagiosadmin
        contact_groups                  +xi_dig_dummy_contact_group
        register                        1
        }

define service {
        host_name                       ${Hostname}
        service_description             DRV_C_Usage
        use                             dig_srv_win_drv_c_usage_prio${Prio}
        servicegroups                   +all_svc_dummy_servicegroup
        check_period                    xi_timeperiod_24x7
        notification_period             xi_timeperiod_24x7
        contacts                        +nagiosadmin
        contact_groups                  +xi_dig_dummy_contact_group
        register                        1
        }

define service {
        host_name                       ${Hostname}
        service_description             EVT_Application
        use                             dig_srv_win_evt_app_prio2
        servicegroups                   +all_svc_dummy_servicegroup
        check_period                    xi_timeperiod_24x7
        notification_period             xi_timeperiod_24x7
        contacts                        +nagiosadmin
        contact_groups                  +xi_dig_dummy_contact_group
        stalking_options                o,w,c,u,
        register                        1
        }

define service {
        host_name                       ${Hostname}
        service_description             EVT_System
        use                             dig_srv_win_evt_sys_prio2
        servicegroups                   +all_svc_dummy_servicegroup
        check_period                    xi_timeperiod_24x7
        notification_period             xi_timeperiod_24x7
        contacts                        +nagiosadmin
        contact_groups                  +xi_dig_dummy_contact_group
        stalking_options                o,w,c,u,
        register                        1
        }

define service {
        host_name                       ${Hostname}
        service_description             NET_Connections
        use                             dig_srv_win_net_con_prio2
        servicegroups                   +all_svc_dummy_servicegroup
        check_period                    xi_timeperiod_24x7
        notification_period             xi_timeperiod_24x7
        contacts                        +nagiosadmin
        contact_groups                  +xi_dig_dummy_contact_group
        register                        1
        }

define service {
        host_name                       ${Hostname}
        service_description             NSClient_Log_Size
        use                             dig_srv_win_041_files_nsclient_log_prio2
        servicegroups                   +all_svc_dummy_servicegroup
        check_period                    xi_timeperiod_24x7
        notification_period             xi_timeperiod_24x7
        contacts                        +nagiosadmin
        contact_groups                  +xi_dig_dummy_contact_group
        register                        1
        }

define service {
        host_name                       ${Hostname}
        service_description             SRV_Certificates
        use                             dig_srv_win_041_certificates
        servicegroups                   +all_svc_dummy_servicegroup
        check_period                    xi_timeperiod_24x7
        notification_period             xi_timeperiod_24x7
        contacts                        +nagiosadmin
        contact_groups                  +xi_dig_dummy_contact_group
        register                        1
        }

define service {
        host_name                       ${Hostname}
        service_description             SRV_CPU
        use                             dig_srv_win_cpu_stats_1_5_15_prio2
        servicegroups                   +all_svc_dummy_servicegroup
        check_period                    xi_timeperiod_24x7
        notification_period             xi_timeperiod_24x7
        contacts                        +nagiosadmin
        contact_groups                  +xi_dig_dummy_contact_group
        register                        1
        }

define service {
        host_name                       ${Hostname}
        service_description             SRV_Memory
        use                             dig_srv_win_mem_physical_95_98_prio2
        servicegroups                   +all_svc_dummy_servicegroup
        check_period                    xi_timeperiod_24x7
        notification_period             xi_timeperiod_24x7
        contacts                        +nagiosadmin
        contact_groups                  +xi_dig_dummy_contact_group
        register                        1
        }

define service {
        host_name                       ${Hostname}
        service_description             SRV_Ping
        use                             dig_srv_win_ping_prio2
        servicegroups                   +all_svc_dummy_servicegroup
        check_period                    xi_timeperiod_24x7
        notification_period             xi_timeperiod_24x7
        contacts                        +nagiosadmin
        contact_groups                  +xi_dig_dummy_contact_group
        register                        1
        }

define service {
        host_name                       ${Hostname}
        service_description             SRV_Uptime
        use                             dig_srv_win_uptime_prio2
        servicegroups                   +all_svc_dummy_servicegroup
        check_period                    xi_timeperiod_24x7
        notification_period             xi_timeperiod_24x7
        contacts                        +nagiosadmin
        contact_groups                  +xi_dig_dummy_contact_group
        register                        1
        }

define service {
        host_name                       ${Hostname}
        service_description             SVC_Windows
        use                             dig_srv_win_svc_windows
        servicegroups                   +all_svc_dummy_servicegroup
        check_period                    xi_timeperiod_24x7
        notification_period             xi_timeperiod_24x7
        contacts                        +nagiosadmin
        contact_groups                  +xi_dig_dummy_contact_group
        register                        1
        }
So, as you can see I used variables for everything that should be substituted. Next the only thing you need is a small Bash script which takes some arguments that you replace in your base config. This is an example Bash script which takes 6 parameters and replaces the variables in the base config with them:

Code: Select all

# Script name: naf_add_server_windows.sh
# Version: 0.15.02.15
# Author: Willem D'Haese
# Created on: 15/01/2015
# Purpose: Bash script to process host config files and dynamically update hostgroups
# History:
#       15/01/2015 => Creation date
#       05/02/2015 => Testing
#       12/02/2015 => Finished script, verified to work locally
#       15/02/2015 => Port to Reactor, in test
# Copyright:
# This program is free software: you can redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.You should have received a copy of the GNU
# General Public License along with this program.  If not, see <http://www.gnu.org/licenses/>.

Hostname=$(echo $1 | tr '[:upper:]' '[:lower:]')
Ip=`dig +short $Hostname | awk '{ print ; exit }'`
Prio=$2
Infra=$3
Loc=$4
Os=$5
Role=$6
ScriptDirectory=$(cd "$( dirname "$0" )" && pwd)
# Nagios import folder (or temporary testfolder)
Nagios_Import_Folder=/root/willemsworkspace/nagioscfgs/
# Nagios_Import_Folder=/usr/local/nagios/etc/import/
Nagios_Host_Folder=/usr/local/nagios/etc/hosts/

echo "Hostname: $Hostname"
echo "Ip: $Ip"
echo "Prio: $Prio"
echo "Infra: $Infra"
echo "Loc: $Loc"
echo "Os: $Os"
echo "Role: $Role"
echo "Script Directory: $ScriptDirectory"
echo "Location ${Nagios_Import_Folder}$Hostname.cfg"

cp $ScriptDirectory/nagios_cfg_base_windows.cfg ${ScriptDirectory}/${Hostname}_Base.cfg
sed -e "s/\${Hostname}/$Hostname/" -e "s/\${Ip}/$Ip/" -e "s/\${Prio}/$Prio/" -e "s/\${Infra}/$Infra/" -e "s/\${Loc}/$Loc/" -e "s/\${Os}/$Os/" -e "s/\${Role}/$Role/" ${ScriptDirectory}/${Hostname}_Base.cfg > ${Nagios_Import_Folder}$Hostname.cfg

echo "Result:"
cat ${Nagios_Import_Folder}$Hostname.cfg

if [ $# -lt 2 ]
then
        echo "naf_add_server_windows.sh:"
        echo "This script is designed to create a basic Nagios host and service configuration file and needs 6 parameters"
        echo "Usage:"
        echo "          naf_add_server_windows.sh"
        echo "Parameters:"
        echo "          1) hostname: Full Nagios hostname, eg server01.domain.local"
        echo "          2) priority: Host priority, only 1, 2 or 3 supported"
        echo "          3) infrastructure: virtual or physical supported"
        echo "          5) location: ac or dg supported"
        echo "          4) os: 2003, 2008, 2012 supported"
        echo "          5) role: role of the server"
        echo
        exit 1
fi

echo "### ${Nagios_Import_Folder}$Hostname.cfg created"

echo "### Importing Nagios config file:"
#cd /usr/local/nagiosxi/scripts
#./reconfigure_nagios.sh
#nagios_exit_code=$?
#echo "### Import ran, exit code: $nagios_exit_code"
#exit $nagios_exit_code

I commented out the ./reconfigure_nagios.sh for now as I'm running a similar script with Reactor. Reactor will look into our inventory database every 60 minutes and check for newly added servers, which will trigger an event chain and build the config file, import them into Nagios XI, install NSCLient, generate the nsclient.ini config file with all the commands and realtime event exclusions it needs, update the nsclient scripts folder and create a report. The only thing I need to add is a script that queries all the drive letters used on a Windows server, but that should be a piece of cake. (ah and I still need to add parent parameter)

I hope the above helps.. The only thing I regret is that I did not do this earlier lol.You will of course need to establish a baseline config of your own. (templates and hostgroups)

I made a GitHub page for it in case you would be interested in future additions. https://github.com/willemdh/naf_add_server_windows

And I will try to add some more documentation how to use it.

Grtz

Willem
Last edited by WillemDH on Sun Feb 15, 2015 11:49 am, edited 1 time in total.
Nagios XI 5.8.1
https://outsideit.net
mp4783
Posts: 116
Joined: Wed May 14, 2014 11:11 am

Re: Model After

Post by mp4783 »

If you want to truly "clone" a host, then you need to go beyond creating new host and service configuration files. You also need to consider the hostgroup, servicegroup, dependency, and escalation files. This is what I'm doing (or at least trying to do) currently.

I agree that modifying the Nagios XI configuration via external configuration files appears to be fairly straightforward, but as you expand beyond simply adding hosts (e.g., deleting hosts, adding services to hosts, etc.), it gets far more complicated, particularly if you want very deterministic behavior in your utility. Just going through this development has taught me a great deal about how Nagios XI works and has also exposed some of the deficiencies in external host management automation. For instance, the version of Nagios XI I'm using doesn't consistently delete hosts and services via the nagiosql_delete_host.php and nagiosql_delete_service.php utilities. Sometimes it works, and sometimes it doesn't.

Why? Who knows, but if you want to be absolutely certain that what your automation asks Nagios to do is actually done, then you have to go well beyond evaluation the exit code from the Nagios supplied utilities. After reconfiguration, you need to actually check if the operation was performed. This means additional code to perform the checks and in the case of deleting a host, if you delete the services successfully, but the host then doesn't delete (this has happened to me), you need a mechanism to restore the configuration to its original state. If you think through this further, you'll see the challenges. I started out with around 100 lines of code to perform a host addition and I'm now at nearly 1000 and I've got two functions (cloning a host and controlling event handler state) working reliably.

Maybe some day the good folks at Nagios will put a real API (i.e. web service) on the front of Nagios so we can all stop building the same tools over and over again. The simple fact is that today, in my opinion, you can't easily do with external utilities what you can do through the GUI.
Locked