[hobbit] NKedit and Instructions

Henrik Stoerner henrik at hswn.dk
Fri Jul 21 11:24:27 CEST 2006


On Thu, Jul 20, 2006 at 07:09:26PM -0400, Epp, Matthew Contractor PEO EIS AKO wrote:
> The one feature I'm focusing on right now is similar to the "Instructions"
> section handled by NKedit. In my custom BB, I edited a section of
> dohostsvc.c to read in files containing plain text or html. This content
> gets placed at the bottom of any page generated from bb-dohostsvc.sh.
[snip]
> What I need to do now is decide how best to proceed with setting this up in
> Hobbit. I'd like to be able to edit the content from the web interface
> somehow. The "Instruction" field in the existing nkedit is good for short
> comments, but we've been using long descriptive html output with web links
> and such. With some experimentation, I found that you can do the same thing
> in nkedit, but you have to remove any special tags like nbsp; and all
> newline characters or it makes the hobbit-nkview.cfg file unreadable.
> 
> I'm going to start looking at the source for bb-hostsvc.sh tomorrow to see
> where I'd need to make changes, but I wanted to throw this out there to see
> if anyone had any thoughts. If anyone else would also like my existing code
> for BB, I can post that. :)

You're welcome to look at the source code, but this particular bit of
Hobbit is not one of the prettier in terms of how it's implemented :-)
Eventually you will end up in lib/htmllog.c and try to tweak that.

However, I think you could do this without changing a single line of
code in Hobbit. The ~hobbit/server/web/hostsvc_footer is already
inserted at the bottom of all the status pages (in the default setup,
it's just a link to bb_footer, but copy that and make your own file). 

You can implement your custom instructions by adding an HTML "object" to 
that file; you can get the hostname and columnname of the host being
viewed by using &BBHOST and &BBSVC placeholders. So you can use this 
as parameters to a CGI script that delivers your instructions for this
specific host+test combination, and by embedding it in an <object>
section, it will automatically be shown as part of the status page.

E.g. in the hostsvc_footer you add

    <center>
      <object 
           data="&CGIBINURL/instructions.sh?HOST=&BBHOST&SVC=&BBSVC"
           type="text/html" width="60%">
              No instructions
      </object>
    </center>

near the top of the hostsvc_footer filer.

Your "instructions.sh" script would need to grab the QUERY_STRING
environment variable which holds the HOST and SVC parameters, match
those against your configuration file, and output an HTML document 
with the instructions. A simple shell script would be something like
(note that writing GCI shell scripts are a bad idea, security-wise):

#!/bin/sh

set `echo "$QUERY_STRING" | sed -e 's!&! !g'`

while test "$1" != ""; do
    case "$1" in
      HOST=*)
         HOSTNAME=`echo $1 | cut -d= -f2`
	 ;;
      SVC=*)
         SERVICE=`echo $1 | cut -d= -f2`
	 ;;
    esac

    shift
done

echo "Content-type: text/html"
echo ""
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"
echo "<html><head><title>Instructions</title></head>"
echo "<body bgcolor=\"#ffffff\">"
echo "These are the instructions for host $HOSTNAME / service $SERVICE"
echo "</body></html>"
echo ""

exit 0


Similar things can be written in Perl, Python, C or whatever your
preferred language may be. Note that setting a <font> or BGCOLOR is
necessary; my first tests of this ended up with black-on-black which
is not easy to read :-)

One nice aspect of this is that you have completely de-coupled the
maintenance of the instructions from Hobbit. If you have a content
management system for uploading the instructions, you can use that to
maintain the data. Or any other tool which is appropriate.


Regards,
Henrik




More information about the Xymon mailing list