====== Xymon Notes Editor ====== ^ Author | [[ solitaryr@gmail.com | Galen Johnson ]] | ^ Compatibility | Xymon 4.2, Xymon 4.3| ^ Requirements | Perl, HTML::FromText, perl-CGI | ^ Download | None | ^ Last Update | 2017-12-05 | ===== Description ===== A web-based editor for modifying your server notes files in Xymon. Xymon's built-in notes viewer will pick up any changes you make. ===== Installation ===== * Install the prerequisite perl modules * Create the notesdata directory ($HOBBITSERVER/etc/notesdata) with ownerships and permissions for your webserver to write to it. mkdir -m 775 /usr/local/hobbit/server/etc/notesdata chgrp apache /usr/local/hobbit/server/etc/notesdata * Update the code for your paths * Put the header and footer file under $HOBBITSERVER/web * Put the bbnote_editor.cgi script under the $HOBBIT/cgi-secure * Update your Administration links in $HOBBITSERVER/www/menu/menu_items.js with ['Edit Notes', '/hobbit-seccgi/bbnote_editor.cgi'], ***UPDATE: ** Ubuntu or Debian users should modify this file instead /etc/hobbit/web/menu.cfg * Insert the following line in Administration section Edit Notes | \ * For xymon 4.3.5 insert following line in $XYMONHOME/server/etc/xymonmenu.cfg Edit Notes | ===== Source ===== ==== notes_header ==== &BBBACKGROUND : Xymon - Notes @ &BBDATE
 
&HOBBITLOGO
Current Status
&BBDATE


==== notes header for 4.3 ==== Xymon - Notes &XYMONBODYHEADER
 
&XYMONLOGO
Current Status


==== notes_footer ====


Xymon Monitor &HOBBITDREL
==== notes_footer for 4.3 ====


Xymon &XYMONDREL
==== bbnote_editor.cgi ==== #!/usr/bin/perl ############################################# # Name: bbnote_editor.cgi # Xymon update: Galen Johnson # Original Author: Chris Naude # Purpose: Manage HTML notes files # Version: 1.0 # The text2html module can be downloaded from CPAN ############################################# use strict; use CGI ":standard"; use HTML::FromText; # Your $BBHOME my $bb_home = "/usr/local/hobbit/server"; # hobbit config file my $hobbitcfg="/usr/local/hobbit/server/etc/hobbitserver.cfg"; # The web path to gifs. my $bb_gifs = "/hobbit/gifs"; # The main web path for bb display. my $bb_web = "/hobbit/"; # The actual www notes dir on the server my $bb_notes = "$bb_home/www/notes"; # This is where the data files are stored. # Not to be confused with the default notes dir. my $bb_notesdata = "$bb_home/etc/notesdata"; my $bb_header = "$bb_home/web/notes_header"; # Change this if needed. my $bb_footer = "$bb_home/web/notes_footer"; # Change this if needed. #Standard bb-hosts file my $bb_hosts = "$bb_home/etc/bb-hosts"; my $bb_showhosts = "$bb_home/bin/bbhostshow"; # No changes needed below. my $color = "blue"; my %hosts; my $cmd = param("cmd"); my $host = param("host"); $host =~ s/(.*?)\///g; $host =~ s/(\.html)$//g; my $note = param("note"); my @lines; # Set up the environment variables and dynamic variables from hobbitserver.cfg foreach (`. $hobbitcfg; set`) { chomp; my ($var,$val) = /^\s*(.*?)\s*=\s*(.*)/; $ENV{$var} = $val; } sub print_notesdata { open (NOTESDATA, "<$bb_notesdata/${host}") or &print_error("I can't read from $bb_notesdata/$host!"); while () { print; } close NOTESDATA; } sub write_notesdata { open (NOTESDATA, ">$bb_notesdata/$host") or &print_error("I can't write to $bb_notesdata/$host!"); print NOTESDATA $note; close NOTESDATA; } sub make_note { my ($color) = @_; my $note = "$bb_notes/${host}.html"; open (NOTE, ">$note") or &print_error("I can't open $note for writing!"); select NOTE; &print_header($color); &print_notesdata; &print_footer($color); select STDOUT; close NOTE; } sub save_note { &write_notesdata; &make_note('blue'); &get_note; print '
Note saved.

'; &print_note; } sub edit_note { if ($cmd =~ /add html/) { my $t2h = HTML::FromText->new({ blockcode => 1, lines => 1, tables => 1, bullets => 1, numbers => 1, urls => 1, email => 1, bold => 1, underline => 1, }); $note = $t2h->parse( $note ); #$note =~ s/\n/
/sgi; # } if ($cmd =~ /strip html/) { $note =~ s/<.*?>//sgi; } print <
HTML } sub print_note { print <

$host [$hosts{$host}]

HTML if ($lines[0]) { print @lines; print <
HTML } elsif ($cmd =~ /preview/) { print <
HTML } else { print <
HTML } print <
HTML } sub print_error { my $error = shift; print "

$error

"; } sub get_note { if ( -s "$bb_notesdata/$host") { open (NOTE, "<$bb_notesdata/$host") or &print_error("I can't open $bb_notesdata/$host for reading!"); while (my $note = ) { push @lines, $note; } close NOTE; } } sub print_menu{ print '

'; for my $host(sort keys %hosts) { print < HTML } print '

Xymon Notes

$host$hosts{$host}
'; } sub get_hosts{ open (HOSTS, "-|", $bb_showhosts, $bb_hosts) or &print_error("I can't open $bb_hosts!"); while () { if (/^(\d+\.\d+\.\d+\.\d+)\s+(.*?)\s+/) { $hosts{$2} = $1; } } close HOSTS; } sub print_header { my $color = shift; print "Content-type: text/html; charset=iso-8859-1\n\n"; open (HEAD, "<$bb_header") or &print_error("I can't open $bb_header for reading!"); while () { # It's a bit hard to edit with a refresh ;) if (/META/i && /HTTP-EQUIV/i && /REFRESH/i && /CONTENT/i) { s/<(.*?)>//g; } s/&HOBBITLOGO/$ENV{'HOBBITLOGO'}/g; s/&BBBACKGROUND/$color/g; s/&BBMENUSKIN/$ENV{'BBMENUSKIN'}/g; s/&BBPAGEPATH/$ENV{'BBPAGEPATH'}/g; s/&BBSKIN/$ENV{'BBSKIN'}/g; s/&BBDATE/$ENV{'BBDATE'}/g; print; } close HEAD; } sub print_footer{ open (FOOT, "<$bb_footer") or &print_error("I can't open $bb_footer for reading!"); while () { s/&BBMENUSKIN/$ENV{'BBMENUSKIN'}/g; s/&HOBBITDREL/$ENV{'HOBBITDREL'}/g; print; } close FOOT; } # Main my ($oldbar) = $|; my $cfh = select (STDOUT); $| = 1; &get_hosts; &print_header($color); # I like blue ;) if ($cmd =~ /edit|html/) { &get_note; &edit_note; } elsif ($cmd eq 'view') { &get_note; &print_note; } elsif ($cmd eq 'preview') { &print_note; } elsif ($cmd eq 'preview as html') { &print_note; } elsif ($cmd eq 'save') { &save_note; } else { &print_menu; } &print_footer; $| = $oldbar; select ($cfh);
==== bbnote_editor.cgi for 4.3 ==== #!/usr/bin/perl # ############################################# # Name: bbnote_editor.cgi # Xymon update: Galen Johnson # Original Author: Chris Naude # Purpose: Manage HTML notes files # Version: 1.0 # The text2html module can be downloaded from CPAN ############################################# use strict; use CGI ":standard"; use HTML::FromText; # Your $XYMONHOME my $xymon_home = "/usr/share/xymon"; my $xymon_cmd = "$xymon_home/bin/xymon"; # xymon config file my $xymoncfg = "$xymon_home/etc/xymonserver.cfg"; # The actual www notes dir on the server my $xymon_notes = "/var/www/xymon/notes"; # This is where the data files are stored. # Not to be confused with the default notes dir. my $xymon_notesdata = "$xymon_home/etc/notesdata"; my $xymon_header = "$xymon_home/web/notes_header"; # Change this if needed. my $xymon_footer = "$xymon_home/web/notes_footer"; # Change this if needed. #Standard hosts.cfg file my $xymon_hosts = "$xymon_home/hosts.cfg"; my $xymon_menu = "$xymon_home/etc/xymonmenu.cfg"; # No changes needed below. my $version = "4.3.28"; my $color = "blue"; my %hosts; my $cmd = param("cmd"); my $host = param("host"); $host =~ s/(.*?)\///g; $host =~ s/(\.html)$//g; my $note = param("note"); my @lines; # Set up the environment variables and dynamic variables from xymonserver.cfg foreach (`$xymon_home/bin/xymoncmd env | /usr/bin/grep XYMON`) { chomp; next if $_ =~ /^directory/; my ($var,$val) = /^\s*(.*?)\s*=\s*(.*)/; $ENV{$var} = $val; } sub print_notesdata { open (NOTESDATA, "<$xymon_notesdata/${host}") or &print_error("I can't read from $xymon_notesdata/$host!"); while () { print; } close NOTESDATA; } sub write_notesdata { open (NOTESDATA, ">$xymon_notesdata/$host") or &print_error("I can't write to $xymon_notesdata/$host!"); print NOTESDATA $note; close NOTESDATA; } sub make_note { my ($color) = @_; my $note = "$xymon_notes/${host}.html"; open (NOTE, ">$note") or &print_error("I can't open $note for writing!"); select NOTE; &print_header($color); &print_notesdata; &print_footer($color); select STDOUT; close NOTE; } sub save_note { &write_notesdata; &make_note('blue'); &get_note; print '
Note saved.

'; &print_note; } sub edit_note { if ($cmd =~ /add html/) { my $t2h = HTML::FromText->new({ blockcode => 1, lines => 1, tables => 1, bullets => 1, numbers => 1, urls => 1, email => 1, bold => 1, underline => 1, }); $note = $t2h->parse( $note ); #$note =~ s/\n/
/sgi; # } if ($cmd =~ /strip html/) { $note =~ s/<.*?>//sgi; } print <

$host [$hosts{$host}]


HTML } sub print_note { print <

$host [$hosts{$host}]

HTML if ($lines[0]) { print @lines; print <
HTML } elsif ($cmd =~ /preview/) { print <
HTML } else { print <
HTML } print <
HTML } # sub print_error { my $error = shift; print "

$error

"; } sub get_note { if ( -s "$xymon_notesdata/$host") { open (NOTE, "<$xymon_notesdata/$host") or &print_error("I can't open $xymon_notesdata/$host for reading!"); while (my $note = ) { push @lines, $note; } close NOTE; } } sub print_menu { print '

'; for my $host(sort keys %hosts) { print < HTML } print '

Xymon Notes

$host$hosts{$host}
'; } sub get_hosts { open (HOSTS, "-|", $xymon_cmd, '127.0.0.1', 'hostinfo') or &print_error("I can't open $xymon_hosts!"); while () { my ($hostname, $hostip, @dummy) = split('\|'); $hosts{$hostname} = $hostip; } close HOSTS; } sub print_header { my $color = shift; print "Content-type: text/html; charset=iso-8859-1\n\n"; open (HEAD, "<$xymon_header") or &print_error("I can't open $xymon_header for reading!"); while () { # It's a bit hard to edit with a refresh ;) if (/META/i && /HTTP-EQUIV/i && /REFRESH/i && /CONTENT/i) { s/<(.*?)>//g; } s/&XYMONLOGO/$ENV{'XYMONLOGO'}/g; s/&XYMONBACKGROUND/$color/g; s/&XYMONBODYCSS/$ENV{'XYMONBODYCSS'}/g; s/&XYMONBODYMENUCSS/$ENV{'XYMONBODYMENUCSS'}/g; s/&XYMONMENUSKIN/$ENV{'XYMONMENUSKIN'}/g; s/&XYMONPAGEPATH/$ENV{'XYMONPAGEPATH'}/g; s/&XYMONSKIN/$ENV{'XYMONSKIN'}/g; s/&XYMONDATE/$ENV{'XYMONDATE'}/g; if (/&XYMONBODYHEADER/) { s/&XYMONBODYHEADER//g; open (MENU, "<$xymon_menu") or &print_error("I can't open $xymon_menu for reading!"); while (
) { s/\$XYMONSERVERWWWURL/$ENV{'XYMONSERVERWWWURL'}/g; s/\$XYMONSERVERCGIURL/$ENV{'XYMONSERVERCGIURL'}/g; s/\$XYMONSERVERSECURECGIURL/$ENV{'XYMONSERVERSECURECGIURL'}/g; print; } close MENU; } print; } close HEAD; } sub print_footer { open (FOOT, "<$xymon_footer") or &print_error("I can't open $xymon_footer for reading!"); while () { s/&XYMONMENUSKIN/$ENV{'XYMONMENUSKIN'}/g; s/&XYMONDREL/$version/g; print; } close FOOT; } # Main my ($oldbar) = $|; my $cfh = select (STDOUT); $| = 1; &get_hosts; &print_header($color); # I like blue ;) if ($cmd =~ /edit|html/) { &get_note; &edit_note; } elsif ($cmd eq 'view') { &get_note; &print_note; } elsif ($cmd eq 'preview') { &print_note; } elsif ($cmd eq 'preview as html') { &print_note; } elsif ($cmd eq 'save') { &save_note; } else { &print_menu; } &print_footer; $| = $oldbar; select ($cfh); ===== Known Bugs and Issues ===== ===== To Do ===== ===== Credits ===== *Chris Naude who wrote the [[ http://www.deadcat.net/viewfile.php?fileid=943 | original BB script ]] ===== Changelog ===== * **2012/01/03** * Adjustments made to make it work and display properly in xymon 4.3.x. My thanks goes to KVDO * for helping me out with the javascript code and everybody that worked on this add-on. * Note: Working but code not perfect. * **2010-11-03** * Removed the local statement on line 224 in the cgi script as it gave errors when compiling. * Changed into * **2010-08-14** * Minor modification to explicitly set the package for local variables (ie, add "my") * **2009-11-26** * Updated the installation section. Ubuntu/Debian uses menu.cfg instead * **2007-07-02** * Added code to force Perl to flush its buffers after each output statement. This will, hopefully, address any 'premature end of script headers' errors. * **2007-05-05** * Updated to use strict * Config variables are added to environment * Capture hosts in include files * **2007-05-01** * Initial release