# On the new (pending) nagios module

**URL:** <https://forum.ansible.com/t/on-the-new-pending-nagios-module/11834>\
**Category:** Ansible Project\
**Created:** [August 28, 2012, 12:52am UTC](https://forum.ansible.com/t/on-the-new-pending-nagios-module/11834 "2012-08-28T00:52:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim\_Bielawa](https://avatars.discourse-cdn.com/v4/letter/t/ed8c4c/32.png) [@Tim\_Bielawa](https://forum.ansible.com/u/Tim_Bielawa)\
**Post date:** [August 28, 2012, 12:52am UTC](https://forum.ansible.com/t/on-the-new-pending-nagios-module/11834/1 "2012-08-28T00:52:14Z")

</div>

Oh hi,

So you may have heard by now that I've ported my func nagios module  
into an ansible module. [1] I thought I'd start a discussion on the  
lists to see if anyone is testing it, or has questions. And to just  
generally spread the word around.

What all functionality does the module encompass?

- Setting downtime  
- Setting alerts

Right now, as it's implemented in Ansible, the functionality is  
limited to HOSTS and their associated services only.

Nagios also has the concepts of hostgroups and servicegroups. The  
original func module has methods to work with these concepts as well.  
In reality though, the ansible module has all of the same  
functionality. Difference being, the ansible module only exposes ways  
to interact with hosts in nagios. If you read the source, you'll see  
about two dozen unused methods for handling everything the module  
already does for hosts, but for service/hostgroups as well.

I brought that up to see if there is interest in exposing that  
functionality as well via the ansible module. Or... if somebody wants  
to take it on as a challenge and do it themselves, they are more than  
welcome to.

How can you use it?

In playbooks this is an action that you will require a delegate host  
for. The delegate is going to be your nagios server. Your action will  
need to set the host parameter to $inventory\_hostname (or whatever you  
need to schedule downtime for). The syntax is this simple:

&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;- name: downtime for a host  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;action: nagios action=downtime minutes=5 services=httpd,nfs  
host=$inventory\_hostname  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;delegate\_to: nagios.example.com

And with just that you've scheduled 5 minutes of downtime on the  
current host for the httpd and nfs services!

How about on the command line? Well, because you have to delegate the  
action you can only do one host at a time, but that shouldn't limit  
it's usefulness:

$ ansible nagios.example.com -u root -m nagios -a  
"action=disable\_alerts service=minecraft host=minecraft01.example.com"

Or maybe you're restarting file serving on your mirror:

$ ansible nagios.example.com -u root -m nagios -a  
"action=disable\_alerts services=rsync,ftp host=mirror01.example.com"

And docs?

It's got 'em. Pull request already submitted [2]

Give 'em a look-over and let me know if there are any areas that need  
some re-working, or if clarity is lacking anywhere.

I hope this is useful to somebody, enjoy!

[1] [https://github.com/ansible/ansible/pull/948](https://github.com/ansible/ansible/pull/948)  
[2] [http://goo.gl/MNARZ](http://goo.gl/MNARZ)

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [August 28, 2012, 2:07am UTC](https://forum.ansible.com/t/on-the-new-pending-nagios-module/11834/2 "2012-08-28T02:07:39Z")

</div>

This will be VERY useful for reporting minecraft outages 🙂

Note Tim also supplied an update to the docs, which is available here – [http://ansible.github.com/modules.html#nagios](http://ansible.github.com/modules.html#nagios)

–Michael

---

<div class="post-metadata">

**Author:** ![Andreas\_Davour](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@Andreas\_Davour](https://forum.ansible.com/u/Andreas_Davour)\
**Post date:** [August 28, 2012, 7:48am UTC](https://forum.ansible.com/t/on-the-new-pending-nagios-module/11834/3 "2012-08-28T07:48:48Z")

</div>

So, the nagios server you are delegatin to, it only needs a ssh  
connection and no ansible installed there, right?

-andreas

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [August 28, 2012, 11:49am UTC](https://forum.ansible.com/t/on-the-new-pending-nagios-module/11834/4 "2012-08-28T11:49:12Z")

</div>

> So, the nagios server you are delegatin to, it only needs a ssh  
> connection and no ansible installed there, right?

Correct.

---

<div class="post-metadata">

**Author:** ![Tim\_Bielawa](https://avatars.discourse-cdn.com/v4/letter/t/ed8c4c/32.png) [@Tim\_Bielawa](https://forum.ansible.com/u/Tim_Bielawa)\
**Post date:** [August 28, 2012, 2:22pm UTC](https://forum.ansible.com/t/on-the-new-pending-nagios-module/11834/5 "2012-08-28T14:22:29Z")

</div>

> This will be VERY useful for reporting minecraft outages 🙂
> 
> Note Tim also supplied an update to the docs, which is available here --  
> [http://ansible.github.com/modules.html#nagios](http://ansible.github.com/modules.html#nagios)
> 
> --Michael
> 
> > Oh hi,

...

> > I hope this is useful to somebody, enjoy!
> > 
> > [1] [https://github.com/ansible/ansible/pull/948](https://github.com/ansible/ansible/pull/948)  
> > [2] [http://goo.gl/MNARZ](http://goo.gl/MNARZ)
> > 
> > --  
> > --Tim Bielawa

Minor update, the module now attempts to 'be smart' and locate your  
command file for you.

There is basic search functionality added which attempts to find the  
nagios configuration file on your system. This is based off a list of  
known locations people store their nagios.cfg file. [1]

It is pretty easy to update the list if you find some odd-ball case  
where the module can't locate your config file for you.

Enjoy!

[1] [https://github.com/ansible/ansible/blob/devel/library/nagios#L51](https://github.com/ansible/ansible/blob/devel/library/nagios#L51)
