Generating Nagios LDAP Schema

lilesb at ijet.com lilesb at ijet.com
Fri Jan 9 08:04:25 CET 2004


I promise that the code that follows will not work on your system.  If isn't
safe, and there is no error checking (use at your own risk).  

That being said, it would be almost trivial to generate LDIFs out of nagios
configuration files...

#!/usr/bin/perl
# (c) Bryan Liles <bryan at osesm.com>
# This code is GPL'd.  For the full license check GNU :)
# just include credit to me if you use it in any of your code
#

my $file = shift;
open (F, $file) or die "Can't open $file: $!\n";

my $ir = 0;
my $rt = '';
my @s = ();

my $basedn = "dc=nagios, dc=my, dc=dot, dc=com";
while (<F>) {
    chomp;
    s/^\s+//;
    s/;.*$//;
    next if /^#/;
    next if /^$/;

    if (/^define\ +(\w+)/) {
        $rt = $1;
        $ir = 1;

    } elsif (/^\}/) {
        pS($rt, @s);
        $ir = 0;
        $rt = '';
        @s = ();
    } elsif ($ir) {
        my @t = split(/[\ \t]+/,$_,2);
        push (@s, \@t);
    }
}

sub pS {
    my ($rt, @s) = @_;
    my $cnbase = '';
    my $cn = '';

    $cs{'command'} = 'command_name';
    $cs{'contact'} = 'contact_name';
    $cs{'contactgroup'} = 'contactgroup_name';
    $cs{'host'} = 'host_name';
    $cs{'hostextinfo'} = 'host_name';
    $cs{'hostgroup'} = 'hostgroup_name';
    $cs{'hostgroup'} = 'hostgroup_name';

    if ($cs{$rt}) {
      $cnbase = $cs{$rt};
    } else {
      $cnbase = "nonono";
    }

    foreach my $i (@s) {
        if ($$i[0] =~ /$cnbase/) {
            $cn = $$i[1];
        }
    }
    print "dn: cn=$cn, $basedn\n";
    print "cn=$cn\n";

    foreach my $i (@s) {
        print "nagios_";
        print join (': ',@$i), "\n";
    }
    print "objectclass: $rt\n";
    print "\n\n"
}




then you could import that into your ldap server.  i'm actually preparing to
make this move with a couple of changes.  I'm going to change the server to
add an object of what server this record should live on for distributed
monitoring.  And probally some other things too.  

I also don't think we need a separate list for this.  It could probally move
to nagios-devel or just stay here for maximum viewing.
-----Original Message-----
From: Luke A. Kanies [mailto:luke at madstop.com]
Sent: Sat 1/3/2004 12:23 AM
To: nagios-users at lists.sourceforge.net
Subject: [Nagios-users] Generating Nagios LDAP Schema
 
Hi all,

This is probably more of interest to those who expressed interest in an
LDAP-based config generator....

I've got an example LDAP schema built (you can see it at
http://luke.madstop.com/nagios.schema), but I realized that my mechanism
for generating it is silly.  Basically, I manually went through and
associated the options I knew of with object types.

Obviously, if I'm going to generate a schema based on something else, I
should generate it based on the Nagios code itself, so that if the code
changes the schema also changes (and also so that I actually have all of
the options; I noticed I missed a heckuva a lot).

So, before I went into trying to figure out where the data is (it looks
like it's all defined in xdata/xodtemplate.h), I figured I'd see if anyone
else is already doing something like this.  In fact, it looks like that
xodtemplate.h file itself is possibly even generated (given the weird
syntax and indentation in some cases).

Has anyone used this file to generate anything else?  Is this file itself
generated?  If so, from what, and how?  Is this even the file I want?

Basically, I want to write a script to convert Nagios's object/attribute
relationships into LDAP objectclass/attribute relationships.  I want to
be able to just point this script at a Nagios src repository and have it
build the schema file.

Anyone have any ideas?  I can do it all myself if necessary, but if
someone else already knows of a good way to take advantage of the
xodtemplate.h stuff, I'd appreciate being let in on the secret.

BTW -- to those who expressed interest in LDAP configuration generation:
Should we start a separate list?  I expect there aren't a lot of us, but
we might end up with a decent amount of traffic.  We could just start with
a simple mail alias (I'd be glad to maintain it), and then maybe create a
"real" list later.

Thanks,
Luke

-- 
I am not a vegetarian because I love animals; I am a vegetarian
because I hate plants.                      -- A. Whitney Brown


-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills.  Sign up for IBM's
Free Linux Tutorials.  Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting
any issue. 
::: Messages without supporting info will risk being sent to /dev/null

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.monitoring-lists.org/archive/users/attachments/20040109/0e0869f8/attachment.html>


More information about the Users mailing list