[Nagiosplug-devel] Creating config files from MySQL database.....

Tony nagios at cerbernet.co.uk
Sun Mar 16 02:15:06 CET 2003


If this is a bit off topic I apologise, but I've explored all avenues to
find a solution to my problem.

I am trying to make it possible to save my config files in a MySQL
database and use a web page to change values.
My main aim is to make it possible for different contact group members
to change their own details, such as contact email/pager details.
So far it's worked well in that I can pull all the relevant information
from all the tables depending on the login of the person logged in.

I'm now trying to export the information from the database and re-build
the config files, this where I'm having a problem. To get things working
well I've had to create a different table entry for any config file
entry that has more than one value, such as multiple members of a
contact group or multiple hosts for a hostgroup.
So when I export the information from the database say for contactgroups
because I have 3 members for one contactrgoup and 2 members for another
contact group I get

define contactgroup{
        contactgroup_name       host-contacts
        alias                   Contacts group for Hosts
        members                 host-pager
}

define contactgroup{
        contactgroup_name       host-contacts
        alias                   Contacts group for Hosts
        members                 test
}

define contactgroup{
        contactgroup_name       host-contacts
        alias                   Contacts group for Hosts
        members                 host-email
}

define contactgroup{
        contactgroup_name       service-contacts
        alias                   Contacts group for Services
        members                 service-pager
}

define contactgroup{
        contactgroup_name       service-contacts
        alias                   Contacts group for Services
        members                 service-email
}

As you can see there are only 2 contactgroups but 5 entries in the
config file.
I need a way to combined the entries so there are only 2 and insert a
comma between members so it looks like this

define contactgroup{
        contactgroup_name       host-contacts
        alias                   Contacts group for Hosts
        members                 host-pager, host-email, test
}

define contactgroup{
        contactgroup_name       service-contacts
        alias                   Contacts group for Services
        members                 service-pager, service-email
}

I can't do this in MySQL so my only way of doing it is in Perl.
Although I can write Perl scripts and have done so to get MySQL data
from the database to produce web pages, this is a bit beyond me. I know
there are some very good Perl programmers on this list so thought maybe
either someone may have an example of how to do this or may have already
combated this.

Attached is a txt file which has the details from the contactgroups
table in MySQL and also another example of the config file that is
produced with multiple entries.

I would be grateful if anyone has an answer.
Thanks in advance.

Tony
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Nagios-data.txt
URL: <https://www.monitoring-plugins.org/archive/devel/attachments/20030316/4fa5d5aa/attachment.txt>


More information about the Devel mailing list