<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2653.12">
<TITLE>RE: [Nagios-users] Generating Nagios LDAP Schema</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=2>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). </FONT></P>
<P><FONT SIZE=2>That being said, it would be almost trivial to generate LDIFs out of nagios configuration files...</FONT>
</P>
<P><FONT SIZE=2>#!/usr/bin/perl</FONT>
<BR><FONT SIZE=2># (c) Bryan Liles <bryan@osesm.com></FONT>
<BR><FONT SIZE=2># This code is GPL'd. For the full license check GNU :)</FONT>
<BR><FONT SIZE=2># just include credit to me if you use it in any of your code</FONT>
<BR><FONT SIZE=2>#</FONT>
</P>
<P><FONT SIZE=2>my $file = shift;</FONT>
<BR><FONT SIZE=2>open (F, $file) or die "Can't open $file: $!\n";</FONT>
</P>
<P><FONT SIZE=2>my $ir = 0;</FONT>
<BR><FONT SIZE=2>my $rt = '';</FONT>
<BR><FONT SIZE=2>my @s = ();</FONT>
</P>
<P><FONT SIZE=2>my $basedn = "dc=nagios, dc=my, dc=dot, dc=com";</FONT>
<BR><FONT SIZE=2>while (<F>) {</FONT>
<BR><FONT SIZE=2> chomp;</FONT>
<BR><FONT SIZE=2> s/^\s+//;</FONT>
<BR><FONT SIZE=2> s/;.*$//;</FONT>
<BR><FONT SIZE=2> next if /^#/;</FONT>
<BR><FONT SIZE=2> next if /^$/;</FONT>
</P>
<P><FONT SIZE=2> if (/^define\ +(\w+)/) {</FONT>
<BR><FONT SIZE=2> $rt = $1;</FONT>
<BR><FONT SIZE=2> $ir = 1;</FONT>
</P>
<P><FONT SIZE=2> } elsif (/^\}/) {</FONT>
<BR><FONT SIZE=2> pS($rt, @s);</FONT>
<BR><FONT SIZE=2> $ir = 0;</FONT>
<BR><FONT SIZE=2> $rt = '';</FONT>
<BR><FONT SIZE=2> @s = ();</FONT>
<BR><FONT SIZE=2> } elsif ($ir) {</FONT>
<BR><FONT SIZE=2> my @t = split(/[\ \t]+/,$_,2);</FONT>
<BR><FONT SIZE=2> push (@s, \@t);</FONT>
<BR><FONT SIZE=2> }</FONT>
<BR><FONT SIZE=2>}</FONT>
</P>
<P><FONT SIZE=2>sub pS {</FONT>
<BR><FONT SIZE=2> my ($rt, @s) = @_;</FONT>
<BR><FONT SIZE=2> my $cnbase = '';</FONT>
<BR><FONT SIZE=2> my $cn = '';</FONT>
</P>
<P><FONT SIZE=2> $cs{'command'} = 'command_name';</FONT>
<BR><FONT SIZE=2> $cs{'contact'} = 'contact_name';</FONT>
<BR><FONT SIZE=2> $cs{'contactgroup'} = 'contactgroup_name';</FONT>
<BR><FONT SIZE=2> $cs{'host'} = 'host_name';</FONT>
<BR><FONT SIZE=2> $cs{'hostextinfo'} = 'host_name';</FONT>
<BR><FONT SIZE=2> $cs{'hostgroup'} = 'hostgroup_name';</FONT>
<BR><FONT SIZE=2> $cs{'hostgroup'} = 'hostgroup_name';</FONT>
</P>
<P><FONT SIZE=2> if ($cs{$rt}) {</FONT>
<BR><FONT SIZE=2> $cnbase = $cs{$rt};</FONT>
<BR><FONT SIZE=2> } else {</FONT>
<BR><FONT SIZE=2> $cnbase = "nonono";</FONT>
<BR><FONT SIZE=2> }</FONT>
</P>
<P><FONT SIZE=2> foreach my $i (@s) {</FONT>
<BR><FONT SIZE=2> if ($$i[0] =~ /$cnbase/) {</FONT>
<BR><FONT SIZE=2> $cn = $$i[1];</FONT>
<BR><FONT SIZE=2> }</FONT>
<BR><FONT SIZE=2> }</FONT>
<BR><FONT SIZE=2> print "dn: cn=$cn, $basedn\n";</FONT>
<BR><FONT SIZE=2> print "cn=$cn\n";</FONT>
</P>
<P><FONT SIZE=2> foreach my $i (@s) {</FONT>
<BR><FONT SIZE=2> print "nagios_";</FONT>
<BR><FONT SIZE=2> print join (': ',@$i), "\n";</FONT>
<BR><FONT SIZE=2> }</FONT>
<BR><FONT SIZE=2> print "objectclass: $rt\n";</FONT>
<BR><FONT SIZE=2> print "\n\n"</FONT>
<BR><FONT SIZE=2>}</FONT>
</P>
<BR>
<BR>
<BR>
<P><FONT SIZE=2>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. </FONT></P>
<P><FONT SIZE=2>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.</FONT></P>
<P><FONT SIZE=2>-----Original Message-----</FONT>
<BR><FONT SIZE=2>From: Luke A. Kanies [<A HREF="mailto:luke@madstop.com">mailto:luke@madstop.com</A>]</FONT>
<BR><FONT SIZE=2>Sent: Sat 1/3/2004 12:23 AM</FONT>
<BR><FONT SIZE=2>To: nagios-users@lists.sourceforge.net</FONT>
<BR><FONT SIZE=2>Subject: [Nagios-users] Generating Nagios LDAP Schema</FONT>
<BR><FONT SIZE=2> </FONT>
<BR><FONT SIZE=2>Hi all,</FONT>
</P>
<P><FONT SIZE=2>This is probably more of interest to those who expressed interest in an</FONT>
<BR><FONT SIZE=2>LDAP-based config generator....</FONT>
</P>
<P><FONT SIZE=2>I've got an example LDAP schema built (you can see it at</FONT>
<BR><FONT SIZE=2><A HREF="http://luke.madstop.com/nagios.schema" TARGET="_blank">http://luke.madstop.com/nagios.schema</A>), but I realized that my mechanism</FONT>
<BR><FONT SIZE=2>for generating it is silly. Basically, I manually went through and</FONT>
<BR><FONT SIZE=2>associated the options I knew of with object types.</FONT>
</P>
<P><FONT SIZE=2>Obviously, if I'm going to generate a schema based on something else, I</FONT>
<BR><FONT SIZE=2>should generate it based on the Nagios code itself, so that if the code</FONT>
<BR><FONT SIZE=2>changes the schema also changes (and also so that I actually have all of</FONT>
<BR><FONT SIZE=2>the options; I noticed I missed a heckuva a lot).</FONT>
</P>
<P><FONT SIZE=2>So, before I went into trying to figure out where the data is (it looks</FONT>
<BR><FONT SIZE=2>like it's all defined in xdata/xodtemplate.h), I figured I'd see if anyone</FONT>
<BR><FONT SIZE=2>else is already doing something like this. In fact, it looks like that</FONT>
<BR><FONT SIZE=2>xodtemplate.h file itself is possibly even generated (given the weird</FONT>
<BR><FONT SIZE=2>syntax and indentation in some cases).</FONT>
</P>
<P><FONT SIZE=2>Has anyone used this file to generate anything else? Is this file itself</FONT>
<BR><FONT SIZE=2>generated? If so, from what, and how? Is this even the file I want?</FONT>
</P>
<P><FONT SIZE=2>Basically, I want to write a script to convert Nagios's object/attribute</FONT>
<BR><FONT SIZE=2>relationships into LDAP objectclass/attribute relationships. I want to</FONT>
<BR><FONT SIZE=2>be able to just point this script at a Nagios src repository and have it</FONT>
<BR><FONT SIZE=2>build the schema file.</FONT>
</P>
<P><FONT SIZE=2>Anyone have any ideas? I can do it all myself if necessary, but if</FONT>
<BR><FONT SIZE=2>someone else already knows of a good way to take advantage of the</FONT>
<BR><FONT SIZE=2>xodtemplate.h stuff, I'd appreciate being let in on the secret.</FONT>
</P>
<P><FONT SIZE=2>BTW -- to those who expressed interest in LDAP configuration generation:</FONT>
<BR><FONT SIZE=2>Should we start a separate list? I expect there aren't a lot of us, but</FONT>
<BR><FONT SIZE=2>we might end up with a decent amount of traffic. We could just start with</FONT>
<BR><FONT SIZE=2>a simple mail alias (I'd be glad to maintain it), and then maybe create a</FONT>
<BR><FONT SIZE=2>"real" list later.</FONT>
</P>
<P><FONT SIZE=2>Thanks,</FONT>
<BR><FONT SIZE=2>Luke</FONT>
</P>
<P><FONT SIZE=2>-- </FONT>
<BR><FONT SIZE=2>I am not a vegetarian because I love animals; I am a vegetarian</FONT>
<BR><FONT SIZE=2>because I hate plants. -- A. Whitney Brown</FONT>
</P>
<BR>
<P><FONT SIZE=2>-------------------------------------------------------</FONT>
<BR><FONT SIZE=2>This SF.net email is sponsored by: IBM Linux Tutorials.</FONT>
<BR><FONT SIZE=2>Become an expert in LINUX or just sharpen your skills. Sign up for IBM's</FONT>
<BR><FONT SIZE=2>Free Linux Tutorials. Learn everything from the bash shell to sys admin.</FONT>
<BR><FONT SIZE=2>Click now! <A HREF="http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click" TARGET="_blank">http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click</A></FONT>
<BR><FONT SIZE=2>_______________________________________________</FONT>
<BR><FONT SIZE=2>Nagios-users mailing list</FONT>
<BR><FONT SIZE=2>Nagios-users@lists.sourceforge.net</FONT>
<BR><FONT SIZE=2><A HREF="https://lists.sourceforge.net/lists/listinfo/nagios-users" TARGET="_blank">https://lists.sourceforge.net/lists/listinfo/nagios-users</A></FONT>
<BR><FONT SIZE=2>::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. </FONT>
<BR><FONT SIZE=2>::: Messages without supporting info will risk being sent to /dev/null</FONT>
</P>
</BODY>
</HTML>