Easy way to reorganize your nagios config files

Discussions and topics related to the Nagios World Conference 2013 held September 30 - October 3, 2013 in St. Paul, MN. For more information on this conference, visit http://www.nagios.com/events/nagiosworl ... erica/2013

Easy way to reorganize your nagios config files

Postby palli » Mon Sep 30, 2013 9:50 am

Hey everyone,

Just wanted to get this thread started by sharing a code snippet i had to write recently.

Have you ever come across someone old Nagios installation and wanted to reorganize how the configuration files are structured ? Guess what, it turns out its much simpler than you would think.

I will be talking a little bit about this style of problems in a presentation on Thursday, "Adagios - Config management done right". Also i will talk a little bit about web configuration and "how to monitor a whole country with nagios".

Code: Select all
#!/usr/bin/env python
import pynag.Model
from pynag.Model import ObjectDefinition

# cfg_file is where our main nagios config file is
pynag.Model.cfg_file = '/etc/nagios/nagios.cfg'

# pynag_directory is where the new objects will be saved
pynag.Model.pynag_directory = '/tmp/nagios/conf.d'

all_objects = ObjectDefinition.objects.all
# Use this instead if you only want to clean up a single directory
# all_objects = ObjectDefinition.objects.filter(filename__contains='/etc/nagios/all_the_services.cfg')

for i in all_objects:
    print "Copying", i.object_type, i.get_description(), "...",
    # Choose a new filename for our object. get_suggested_filename() means that
    # pynag will suggest a new file name based on object type.
    new_filename = i.get_suggested_filename()
    print "Copied to", new_filename
    # Optionally, delete the original attribute, only uncomment
    # this if you know what you are doing
    # i.delete()

Anyone who has a problem related to manage configuration files, feel free to start a discussion on this thread.
Posts: 2
Joined: Sun Sep 29, 2013 12:53 pm

Return to Nagios World Conference 2013

Who is online

Users browsing this forum: No registered users and 0 guests