Purpose. Target Audience. Summary. Automation Overview. Nagios XI. Automated Host Management

Similar documents
Understanding And Using Configuration Wizards In Nagios XI. This document describes how to use Configuration Wizards in Nagios XI.

Host and Service Status pages provide a Network Traffic Analysis tab

How to Configure And Text Notifications

This document is intended for use by Nagios Administrators that want to use Slack for notifications.

Backing Up And Restoring Nagios Log Server. This document describes how to backup and restore a Nagios Log Server cluster.

Using SSL/TLS with Active Directory / LDAP

This document is intended for use by Nagios XI Administrators who need a boost in I/O performance.

Monitoring Apache Tomcat Servers With Nagios XI

Understanding Notification Escalations

How To Use The Actions Component

Backing Up And Restoring Your Nagios XI System

Purpose. Target Audience. Prerequisites. What Is An Event Handler? Nagios XI. Introduction to Event Handlers

WMLUG July Nagios, PNP4Nagios, and NConf by Patrick TenHoopen

This document covers how to manage fused servers in Nagios Fusion.

Using The Core Config Manager For Service Management

These instructions cover how to install and use pre-compiled binaries to monitor AIX 5.3 using NRPE.

Purpose. Target Audience. Solution Overview NCPA. Using NCPA For Passive Checks

In addition to this document, Nagios administrators should be familiar with the following documentation: Nagios XI Users and Contacts

Nagios User Guide. You can use apt-get to install these packages by running the following commands:

NRPE DOCUMENTATIOND. Copyright (c) Ethan Galstad. Last Updated: 17 November Contents

Nagios XI Host and Service Details Overview

Nagios XI Monitoring Websites With Nagios XI

Understanding The User Macros Component

How To Monitor Apache Cassandra Distributed Databases

Understanding Notification Variables

A Xen Virtual Machine Monitor Plugin for Nagios

Network Management with Nagios

Nagios XI Using The Core Config Manager For Host Management

Storage Made Easy Cloud Appliance installation Guide

Bitnami Coppermine for Huawei Enterprise Cloud

DCLI User's Guide. Data Center Command-Line Interface 2.9.1

An internal CA that is part of your IT infrastructure, like a Microsoft Windows CA

Bitnami Apache Solr for Huawei Enterprise Cloud

This document is intended for use by Nagios XI Administrators who wish to monitor JMX applications.

DCLI User's Guide. Data Center Command-Line Interface

Bitnami JRuby for Huawei Enterprise Cloud

DCLI User's Guide. Modified on 20 SEP 2018 Data Center Command-Line Interface

DCLI User's Guide. Data Center Command-Line Interface 2.7.0

NETCONF Client GUI. Client Application Files APPENDIX

Icinga at Hyves.nl. Jeffrey Lensen System Engineer

Oracle WebLogic Server 12c: Administration I

Bitnami MEAN for Huawei Enterprise Cloud

Link Gateway Initial Configuration Manual

Installing Nagios Log Server with VMware Workstation Player

8.0 Help for Community Managers Release Notes System Requirements Administering Jive for Office... 6

Bitnami Pimcore for Huawei Enterprise Cloud

Monitoring a HPC Cluster with Nagios

Purpose. Target Audience. Windows Machine Requirements. Windows Server Core (No Desktop) Nagios XI. Monitoring Windows Using WMI

RSA NetWitness Logs. Microsoft Network Policy Server. Event Source Log Configuration Guide. Last Modified: Thursday, June 08, 2017

Purpose. Target Audience. Install SNMP On The Remote Linux Machine. Nagios XI. Monitoring Linux Using SNMP

Bitnami ez Publish for Huawei Enterprise Cloud

VMware AirWatch Database Migration Guide A sample procedure for migrating your AirWatch database

Offloading MySQL to Remote Server

Purpose. Target Audience. Installation Overview. Install SDK Prerequisites. Nagios XI. Monitoring VMware With Nagios XI

Migrating the Cisco StadiumVision Director Server Environment to Platform 2 from the Cisco ADE 2140 Series Appliance

Authenticating and Importing Users with AD and LDAP

Lab 1: Accessing the Linux Operating System Spring 2009

Using the Cisco NCS Command-Line Interface

Bitnami Ruby for Huawei Enterprise Cloud

Assuming you have Icinga 2 installed properly, and the API is not enabled, the commands will guide you through the basics:

Bitnami Re:dash for Huawei Enterprise Cloud

Bitnami ProcessMaker Community Edition for Huawei Enterprise Cloud

AWS Quick Start Guide. Launch a Linux Virtual Machine Version

Open Agent Container (OAC)

Authenticating and Importing Users with Active Directory and LDAP

This document is intended for use by Nagios Administrators that want to monitor SNMP devices using an SNMP Walk to discover it's available objects.

Bitnami MySQL for Huawei Enterprise Cloud

NCAP Nagios Collector and Plugin

Offloading NDO2DB To Remote Server

CIS 76 VLab Pod Setup

Progress OpenEdge. > Getting Started. in the Amazon Cloud.

MITEL PERFORMANCE ANALYTICS

VII. Corente Services SSL Client

Bitnami Piwik for Huawei Enterprise Cloud

BIG-IP Virtual Edition and Cloud-Init. Version 13.0

Protection! User Guide. A d m i n i s t r a t o r G u i d e. v L i c e n s i n g S e r v e r. Protect your investments with Protection!

VMware vfabric AppInsight Installation Guide

THE WATCHER. IO- Statistics. Dropping the iostat.cgi agent script (Listing 1) into the CGI directory. web server you want to investigate

<Partner Name> <Partner Product> RSA SECURID ACCESS Implementation Guide. PingIdentity PingFederate 8

Monitoring (with) Puppet. PuppetCamp

Oracle Cloud IaaS: Compute and Storage Fundamentals

Contents. Note: pay attention to where you are. Note: Plaintext version. Note: pay attention to where you are... 1 Note: Plaintext version...

Reset the Admin Password with the ExtraHop Rescue CD

Loadbalancer.org Appliance Administration v4.1.5

Bitnami Tiny Tiny RSS for Huawei Enterprise Cloud

Bitnami Dolibarr for Huawei Enterprise Cloud

Performing Maintenance Operations

CIS 76 VLab Pod Setup

Smart Bulk SMS & Voice SMS Marketing Script with 2-Way Messaging. Quick-Start Manual

WLM1200-RMTS User s Guide

Bitnami OSQA for Huawei Enterprise Cloud

Xcode Release Notes. Apple offers a number of resources where you can get Xcode development support:

Cloud Control Panel (CCP) User Guide

Using Cisco IOS XE Software

AWS Service Catalog. User Guide

BEAWebLogic Server. Node Manager Administrator s Guide

Guide to Deploying VMware Workspace ONE. VMware Identity Manager VMware AirWatch 9.1

op5 Monitor administrator manual

Installation Guide. Contents. Overview. Dell SonicWALL Advanced Reporting Installation Guide. Secure Remote Access. SonicOS

Bitnami TestLink for Huawei Enterprise Cloud

Transcription:

Purpose This document describes how to automate adding and removing hosts and services in Nagios XI from the command line. Target Audience This document is intended for use by Administrators and Developers and is recommended for those who have prior knowledge of scripting and automating solutions. Summary This document will cover the following topics: Automation Overview Including REST API (new in XI 5.x) Key Files and Directory Locations Importing a Configuration File Import Verification and Exit Codes Removing Hosts and Services Automation Overview Some administrators may have need to automate the process of adding and removing hosts and services in for use with cloud computing or large environments where solutions like Puppet or Chef may already be implemented. The procedures below outline how administrators can create their own automation solutions to safely add and remove hosts and services in while still maintaining the integrity of the monitoring environment. Before 5 was released, the method for automatically adding hosts and services was performed by adding Nagios object definition files into the import directory and then running a script. This requires direct access to the host, perhaps via a ssh session. Security is provided by requiring access to the XI server console, permission via the Linux Operating system local users. Page 1 / 11

5 introduced a REST API that allows you to create host and objects using a HTTP post (commonly done with a CURL command). This method can be issued from an external machine, you don't need to be on the XI server to create objects. Security is provided by an API key which is linked to a specific user. Both methods are supported automation methods and will be covered in this documentation. Key Files and Directory Locations The directory locations and key files in are as follows. /usr/local/nagios/etc/import/ Any configuration files in this directory that end with.cfg will automatically be imported into every time Apply Configuration is run from within, or the reconfigure_nagios.sh script is run. /usr/local/nagiosxi/scripts/reconfigure_nagios.sh This script is the command that is executed when Apply Configuration is initiated from the web interface. This script will import files from the import directory, verify configuration, and restart Nagios if verification succeeds. If verification fails, will roll the configuration back to the last working checkpoint. /usr/local/nagiosxi/scripts/nagiosql_delete_host.php Command-line script for host deletion. This script must be run from the /usr/local/nagiosxi/scripts/ directory. /usr/local/nagiosxi/scripts/nagiosql_delete_service.php Command-line script for service deletion. This script must be run from the /usr/local/nagiosxi/scripts/ directory. Page 2 / 11

REST API The REST API (herein refereed to as "API") is completely documented in the web interface. Navigate to Help > REST API Docs. With that in mind, a full explanation will not be covered in this documentation, with the exception of the API Key. The API Key is what provides authentication to users to access the API. A user can find their API Key by clicking their name in the top right of the navigation menu. This will take them to their Account Information page which show them their API Key in a read-only field. NOTE: The API Key may be longer than the field, simply click in the field and press CTRL + A on your keyboard to select it all. An example of a CURL command used to access the API is as follows: curl -XGET "http://10.25.5.2/nagiosxi/api/v1/system/status?apikey=5goacg8s&pretty=1" It will produce output like this: { "instance_id": "1", "instance_name": "localhost", "status_update_time": "2017-01-31 16:37:46", "program_start_time": "2017-01-31 14:20:42", "program_run_time": "8225", "program_end_time": "0000-00-00 00:00:00", "is_currently_running": "1", "process_id": "2819", "daemon_mode": "1", "last_command_check": "1970-01-01 10:00:00", "last_log_rotation": "1970-01-01 10:00:00", "notifications_enabled": "1", Page 3 / 11

"active_service_checks_enabled": "1", "passive_service_checks_enabled": "1", "active_host_checks_enabled": "1", "passive_host_checks_enabled": "1", "event_handlers_enabled": "1", "flap_detection_enabled": "1", "process_performance_data": "1", "obsess_over_hosts": "0", "obsess_over_services": "0", "modified_host_attributes": "0", "modified_service_attributes": "0", "global_host_event_handler": "xi_host_event_handler", "global_service_event_handler": "xi_service_event_handler" Creating Host And Services By Importing A Configuration File Typically automated configuration management will make heavy use of templates. Simpler configuration imports will be easier to maintain and have less potential issues upon import and deletion. When automating a configuration import, we recommend the following: Use one configuration file for a single host and each of it's services Service definitions should only be applied to a single host, not a host list or a hostgroup The.cfg file should be named according to the host name, example: LOC_MASShost_1.cfg Here is an example file called LOC_MASShost_1.cfg: define host{ host_name LOC_MASShost_1 address 127.0.0.1 use xiwizard_generic_host Page 4 / 11

define service{ host_name LOC_MASShost_1 service_description LOC_MASSservice_ping use xiwizard_website_ping_service define service{ host_name LOC_MASShost_1 service_description LOC_MASSservice_dnsip use xiwizard_website_dnsip_service check_command check_xi_service_dns!'-a 127.0.0.1' Place the configuration file into the /usr/local/nagios/etc/import directory. Run the /usr/local/nagiosxi/scripts/reconfigure_nagios.sh script. When this script is run, looks in the import directory and pulls all of the configuration files to either update old versions, or populate new ones. Creating Host And Services By Using API Typically automated configuration management will make heavy use of templates. Simpler API commands will be easier to maintain and have less potential issues upon import and deletion. When use the API, we recommend the following: Service definitions should only be applied to a single host, not a host list or a hostgroup Special characters like $ and! will need to be escaped to prevent the Linux shell from interpreting them, for example: \! API commands use the same directive names as a Nagios config file has, you provide them in the format directive_name=value and separate them using the ampersand (&). Page 5 / 11

For example: address=127.0.0.1&use=xiwizard_generic_host Example commands to create host and services, just like the Config File definitions above: Host Object: curl -XPOST "http://10.25.5.2/nagiosxi/api/v1/config/host? apikey=5goacg8s&pretty=1" -d "host_name=loc_masshost_1&address=127.0.0.1&use=xiwizard_generic_host&force=1& applyconfig=1 Service Ping: curl -XPOST "http://10.25.5.2/nagiosxi/api/v1/config/service? apikey=5goacg8s&pretty=1" -d "host_name=loc_masshost_1&service_description=loc_massservice_ping&use=xiwizar d_website_ping_service&force=1&applyconfig=1" Service DNS: curl -XPOST "http://10.25.5.2/nagiosxi/api/v1/config/service? apikey=5goacg8s&pretty=1" -d "host_name=loc_masshost_1&service_description=loc_massservice_dnsip&use=xiwiza rd_website_dnsip_service&check_command=check_xi_service_dns\!'-a 127.0.0.1'&force=1&applyconfig=1" Page 6 / 11

Import Verification and Exit Codes It is important to monitor the return status of the reconfigue_nagios.sh script. will not apply a broken configuration, so if the configuration verification fails, will restore the configuration files to the last working checkpoint, but the broken configuration will still remain in the database. Detecting failures is crucial, otherwise all future automated changes will likely fail after the first. Each exit code in reconfigure_nagios.sh corresponds to a different stage of the script, and will reveal where the problem occurred. The following are the error codes that reconfigure_nagios.sh will return: 0 no problems detected 1 config verification failed 2 nagiosql login failed 3 nagiosql import failed 4 reset_config_perms failed 5 nagiosql_exportall.php failed (write configs failed) 6 /etc/init.d/nagios restart failed 7 db_connect failed If you get a return code of 0, your new configuration file has been successfully verified as a working configuration and has been accepted by. Page 7 / 11

API Verification and Exit Codes The API itself will produce different output, usually an error message saying a value was missing. For example, the following command is executed: curl -XPOST "http://10.25.5.2/nagiosxi/api/v1/config/service? apikey=5goacg8s&pretty=1" -d "host_name=loc_masshost_1&service_description=loc_massservice_ping&use=xiwizar d_website_ping_service&applyconfig=1" The following output is produced: { "error": "Missing required variables", "missing": [ "max_check_attempts", "check_interval", "retry_interval", "check_period", "notification_interval", "notification_period", "contacts OR contact_groups" ] The output above explains that certain directives are missing. You might notice the command used was very similar to the command executed earlier, except for one difference. The command did not have the &force=1 argument, the command originally issued is using a template and hence those "missing" directives are actually in the template. Using the &force=1 argument allows you to force the API to create the configuration file you submitted to it. Page 8 / 11

Additionally, the curl command does not receive an exit code, because the curl command itself received a valid response from the server. It's up to you to process the data received to ensure it's correct. By default the data received is a JSON object, so you can easily test to see if the "success" or "error" keys exist to ensure the object was created, as if it's executed by an automation system like Puppet or Chef the exit code will usually be 0. Removing Hosts and Services To remove a host from, the host must be removed from the Core Config Manager's database, which will handle the deletion of the physical configuration file as well. A host or service can only be removed after all dependent relationships have been removed. This applies for either automation method used. For the example above, the services for this host must first be deleted. Using Scripts Service can be deleted either by database ID or Config Name, which corresponds to the physical configuration file that it is stored in. This is why it is necessary to name the import file the same as the host name. First change into the directory: cd /usr/local/nagiosxi/scripts This command will delete all the services for the host LOC_MASShost_1 (created earlier):./nagiosql_delete_service.php -config=loc_masshost_1 This will produce a lot of output, the last line of the command should be the most important: 2 services deleted successfully! Page 9 / 11

After the services have successfully been deleted, the host can be removed as well:./nagiosql_delete_host.php -host=loc_masshost_1 Once the host is removed, the new configuration can be applied and verified by running the reconfigure_nagios.sh script:./reconfigure_nagios.sh Using REST API The services need to be individually removed and are deleted by using the Host Name and the Service Description. These commands don't apply the config as there is no need to do this multiple times, when the host is deleted is fine. This command will delete the LOC_MASSservce_ping services for the host LOC_MASShost_1 (created earlier): curl -XDELETE "http://10.25.5.2/nagiosxi/api/v1/config/service? apikey=5goacg8s&pretty=1&host_name=loc_masshost_1&service_description=loc_mass service_ping" This will produce the following output: { "success": "Removed LOC_MASShost_1 :: LOC_MASSservice_ping from the system. Config imported but not yet applied." Page 10 / 11

This command will delete the LOC_MASSservce_dnsip services for the host LOC_MASShost_1 (created earlier): curl -XDELETE "http://10.25.5.2/nagiosxi/api/v1/config/service? apikey=5goacg8s&pretty=1&host_name=loc_masshost_1&service_description=loc_mass service_dnsip" After the services have successfully been deleted, the host can be removed as well: curl -XDELETE "http://10.25.5.2/nagiosxi/api/v1/config/host? apikey=5goacg8s&pretty=1&host_name=loc_masshost_1&applyconfig=1" The output will be as follows: { "success": "Removed LOC_MASShost_1 from the system. Config applied, Nagios Core was restarted." Finishing Up This completes the documentation on automated host and service management in. If you have additional questions or other support related questions, please visit us at our Nagios Support Forums: https://support.nagios.com/forum The Nagios Support Knowledgebase is also a great support resource: https://support.nagios.com/kb Page 11 / 11