Nagios XI + Ansible
Nagios XI + Ansible
Hello,
I would like to use Ansible to automate the addition of monitoring in Nagios XI.
Have you ever experienced this? If yes, do you have any examples?
For example, I wonder whether to use the uri module to interact with the NAgios XI API. If so how could I check if the monitoring already exists before adding it.
Thank you in advance for your advice.
I would like to use Ansible to automate the addition of monitoring in Nagios XI.
Have you ever experienced this? If yes, do you have any examples?
For example, I wonder whether to use the uri module to interact with the NAgios XI API. If so how could I check if the monitoring already exists before adding it.
Thank you in advance for your advice.
Re: Nagios XI + Ansible
For additional documentation on everything discussed below, see the "Help" section of your Nagios XI GUI for additional documentation regarding the REST API.
I thought I kept the playbook but I can't find it. I was using the REST API endpoint api/v1/config/ (with Ansible's uri module) with applyconfig=0 to batch-up config changes. So essentially, the changes would be entered in then, once everything is ready, do the apply config step with applyconfig=1.
Yes!bennyboy wrote:Have you ever experienced this?
Nobennyboy wrote:If yes, do you have any examples?
Limited queries on api/v1/objects/* could be used to see if a particular hostname or service_description is already in-use.bennyboy wrote:If so how could I check if the monitoring already exists before adding it.
Former Nagios employee
https://www.mcapra.com/
https://www.mcapra.com/
Re: Nagios XI + Ansible
Thanks for the input @mcapra!
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Re: Nagios XI + Ansible
Can you create a repository on your GitHub. I want to create couple playbook/role with Nagios help.
Re: Nagios XI + Ansible
Code: Select all
- name: Monitoring Filebeat Service
uri:
url: https://{{ nagios_server }}/nagiosxi/api/v1/config/service?apikey={{ nagios_api_key }}"
body:
host_name: '{{ ansible_nodename }}'
service_description: 'Service Status: Filebeat'
use: '{{ nagios_filebeat_template }}'
force: 1
status_code: 200
body_format: json
method: POST
validate_certs: no
Re: Nagios XI + Ansible
It looks like you have the POST action down. I don't have a Ansible setup currently to test with, but commands to query hosts and services would look like:
curl -XGET "http://nagiosxi/nagiosxi/api/v1/objects ... Y&pretty=1"
curl -XGET "http://nagiosxi/nagiosxi/api/v1/objects ... Y&pretty=1"
curl -XGET "http://nagiosxi/nagiosxi/api/v1/objects ... 2.168.3.38"
curl -XGET "http://nagiosxi/nagiosxi/api/v1/objects ... 2.168.3.38"
curl -XGET "http://nagiosxi/nagiosxi/api/v1/objects ... on=NNA:mem"
The above examples will pull information on for all hosts and services, details on a single host(example host specific to my test environment), details for for all services on a host, and details for a single service a host. Hopefully these will help in your endeavor.
curl -XGET "http://nagiosxi/nagiosxi/api/v1/objects ... Y&pretty=1"
curl -XGET "http://nagiosxi/nagiosxi/api/v1/objects ... Y&pretty=1"
curl -XGET "http://nagiosxi/nagiosxi/api/v1/objects ... 2.168.3.38"
curl -XGET "http://nagiosxi/nagiosxi/api/v1/objects ... 2.168.3.38"
curl -XGET "http://nagiosxi/nagiosxi/api/v1/objects ... on=NNA:mem"
The above examples will pull information on for all hosts and services, details on a single host(example host specific to my test environment), details for for all services on a host, and details for a single service a host. Hopefully these will help in your endeavor.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Re: Nagios XI + Ansible
This is the example I find for adding a new service check in Nagios XI.
Code: Select all
curl -XPOST "https://nagiosxi/nagiosxi/api/v1/config/service?apikey=APIKEY&pretty=1" -d "host_name=testapihost&service_description=PING&check_command=check_ping\!3000,80%\!5000,100%&check_interval=5&retry_interval=5&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin¬ification_interval=5¬ification_period=24x7&applyconfig=1"Re: Nagios XI + Ansible
I don't understand something. I use force: 1 with ansible and I got always the same result. I miss something ?
Code: Select all
ok: [sldwbm0361 -> 127.0.0.1] => {
"access_control_allow_methods": "*",
"access_control_allow_orgin": "*",
"changed": false,
"connection": "close",
"content": "{\"error\":\"Missing required variables\",\"missing\":[\"host_name\",\"service_description\",\"max_check_attempts\",\"check_interval\",\"retry_interval\",\"check_period\",\"notification_interval\",\"notification_period\",\"contacts OR contact_groups\"]}\n",
"content_length": "230",
"content_type": "application/json",
"cookies": {},
"date": "Thu, 01 Mar 2018 22:39:00 GMT",
"invocation": {
"module_args": {
"attributes": null,
"backup": null,
"body": {
"force": "1",
"host_name": "sldwbm0361",
"service_description": "Service Status: Filebeat",
"use": "SAQ_Unix_nonprod_filebeat_services"
},
"body_format": "json",
"client_cert": null,
"client_key": null,
"content": null,
"creates": null,
"delimiter": null,
"dest": null,
"directory_mode": null,
"follow": false,
"follow_redirects": "safe",
"force": false,
"force_basic_auth": false,
"group": null,
"headers": {
"Content-Type": "application/json"
},
"http_agent": "ansible-httpget",
"method": "POST",
"mode": null,
"owner": null,
"regexp": null,
"remote_src": null,
"removes": null,
"return_content": true,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"src": null,
"status_code": [
"200"
],
"timeout": 120,
"unsafe_writes": null,
"url": "https://nagios.saq.qc.ca/nagiosxi/api/v1/config/service?apikey=APIKEY",
"url_password": null,
"url_username": null,
"use_proxy": true,
"validate_certs": false
}
},
"json": {
"error": "Missing required variables",
"missing": [
"host_name",
"service_description",
"max_check_attempts",
"check_interval",
"retry_interval",
"check_period",
"notification_interval",
"notification_period",
"contacts OR contact_groups"
]
},
"msg": "OK (230 bytes)",
"redirected": false,
"server": "Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/5.4.16",
"status": 200,
"url": "https://nagios.saq.qc.ca/nagiosxi/api/v1/config/service?apikey=APIKEY",
"x_powered_by": "PHP/5.4.16"
}Re: Nagios XI + Ansible
The error message says there are missing required variables. Try setting the body to something like:
Code: Select all
"body": {
"force": "1",
"host_name": "sldwbm0361",
"service_description": "Service Status: Filebeat",
"use": "SAQ_Unix_nonprod_filebeat_services"
"max_check_attempts": "5",
"check_interval": "5",
"retry_interval": "1",
"check_period": "24x7",
"notification_interval": "5",
"notification_period": "24x7",
"contacts": "nagiosadmin"
}As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Re: Nagios XI + Ansible
Hi,
I want to use a template. I read I have to use force to be able to do that.
Thank you!
I want to use a template. I read I have to use force to be able to do that.
Thank you!