no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | tutorials:customgraph [2009/02/01 03:09] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | This is another contribution from the Xymon list provided by [[sigurdur@raforninn.is|Sigurður Guðbrandsson]] (www.raforninn.is) | ||
+ | ---- | ||
+ | |||
+ | The problem with parsing is to know what you want to parse. | ||
+ | |||
+ | The first step is to send your information to hobbit and see it displayed. | ||
+ | |||
+ | Second step is to configure hobbitlaunch.cfg file to send the data from the column to your script. | ||
+ | FROM / | ||
+ | < | ||
+ | [rrdstatus] | ||
+ | ENVFILE / | ||
+ | NEEDS hobbitd | ||
+ | CMD hobbitd_channel --channel=status --log=$BBSERVERLOGS/ | ||
+ | | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | The --extra-script is the path to the script that you wish to run to do the parsing. You can only have one there. | ||
+ | |||
+ | Then you have to edit hobbitserver.cfg and add the test to TEST2RRD and GRAPHS variables. | ||
+ | Then either reboot the server or kill hobbit_channel processes (they should restart the next time they are scheduled to run) | ||
+ | |||
+ | To begin to know what you have to parse, just tell the script to write to some file (overwrite, not append .. Unless of course you want it to grow bigger and bigger). It should be very similar to what the web site shows. | ||
+ | Alternatively there should be a way to use the bb program to display it, but I didn't bother finding out how. | ||
+ | |||
+ | Then of course you do your parsing. | ||
+ | I recommend that you read about RRD graphs and how you can display different values (is it a counter, is it a variable like temperature, | ||
+ | |||
+ | You should receive 3 args from hobbit when it runs your script, it behaves so: | ||
+ | < | ||
+ | The messagefile is a temporary file which you shall parse. | ||
+ | |||
+ | The final stage is to output your information to hobbit in a way it understands, | ||
+ | The format is so, note that you don’t have to have the type GAUGE, replace with what you need:< | ||
+ | DS:< | ||
+ | < | ||
+ | < | ||
+ | DS:< | ||
+ | < | ||
+ | < | ||
+ | Etc etc.. | ||
+ | </ | ||
+ | |||
+ | A tip for the wise, I had a lot of struggle with this when I was making it, and then realised that I can't have the dataset names any different in all the files, it has to be static, that is, one name. | ||
+ | |||
+ | Then you should check if there are any RRD files being made. | ||
+ | They should be located in / | ||
+ | |||
+ | Then there comes the fun, to be able to show off your results in a graph. You should edit hobbitgraph.cfg file for that. | ||
+ | Mine looks like this:< | ||
+ | [hitastig] | ||
+ | FNPATTERN hitastig.(.*).rrd | ||
+ | TITLE Hitastig | ||
+ | YAXIS Celsius | ||
+ | DEF: | ||
+ | LINE2: | ||
+ | GPRINT: | ||
+ | GPRINT: | ||
+ | GPRINT: | ||
+ | GPRINT: | ||
+ | </ | ||
+ | |||
+ | The files it expects are hitastig.< | ||
+ | See in the DEF line, the name I chose for the datasets is temperature. (**I remind you again, it needs to be static**) | ||
+ | |||
+ | If you do this successfully, | ||
+ | |||
+ | For reference (and of course to future developers that will read the mailing list archive) I will attach my scripts here so you know what to expect. | ||
+ | |||
+ | dgitemp.pl -- This script reads from digitemp values, names and peak values from the MySQL database and sends them to hobbit.< | ||
+ | # | ||
+ | # This script reads digitemp values and writes them to a # temporary file which the hobbit client sends out to # the Xymon Monitor. | ||
+ | # This script really should be rewritten so it will contain subs for operations. | ||
+ | # That would be much more tidier. | ||
+ | # Written by Sigurdur Gudbrandsson | ||
+ | # sigurdur@raforninn.is | ||
+ | |||
+ | use strict; | ||
+ | use DBI; | ||
+ | |||
+ | # Lets declare our variables | ||
+ | |||
+ | my $db_user = " | ||
+ | my $db_pass = " | ||
+ | my $db_name = " | ||
+ | my $table_meta = " | ||
+ | my $table = " | ||
+ | |||
+ | # We need to get some variables from the environment, | ||
+ | my $BB = $ENV{BB}; | ||
+ | my $BBDISP = $ENV{BBDISP}; | ||
+ | my $MACHINE = $ENV{MACHINE}; | ||
+ | my $BBTMP = $ENV{BBTMP}; | ||
+ | |||
+ | # Change this to whatever you want your test to be named | ||
+ | my $testname = " | ||
+ | |||
+ | # Don't change this or your test will never be green | ||
+ | my $color = " | ||
+ | |||
+ | # Set this to other than 0 if you want to debug | ||
+ | my $debug = 0; | ||
+ | |||
+ | # Lets connect to the database | ||
+ | my $dbh = DBI-> | ||
+ | or die "I cannot connect to dbi: | ||
+ | |||
+ | # Lets get the sensor ID's, names and min/max values | ||
+ | my $sql = " | ||
+ | |||
+ | my $sth = $dbh-> | ||
+ | $sth-> | ||
+ | |||
+ | my (@sensors) = (); | ||
+ | while (my @ary = $sth-> | ||
+ | if ($ary[3] == " | ||
+ | $ary[3] = 0.000; | ||
+ | } | ||
+ | if ($ary[4] == " | ||
+ | $ary[4] = 99.999; | ||
+ | } | ||
+ | push(@sensors, | ||
+ | } | ||
+ | $sth-> | ||
+ | |||
+ | # Now we have all the sensors in a two dimensional array, @sensors | ||
+ | # Also, if there is a NULL value in min or max, it has been substituted with a value | ||
+ | |||
+ | # Now we will get the temperature of each sensor from the database | ||
+ | # and check if the temp is too high or too low. | ||
+ | |||
+ | my $count = 0; | ||
+ | while (@{sensors[$count]}) { | ||
+ | print " | ||
+ | my $sql = " | ||
+ | print "SQL: term is \" $sql \" \n" if ($debug); | ||
+ | my $sth = $dbh-> | ||
+ | $sth-> | ||
+ | $sensors[$count][5] = $sth-> | ||
+ | if ($sensors[$count][5] > $sensors[$count][4]){ | ||
+ | print "IF: status for $sensors[$count][1] is red\n" if ($debug); | ||
+ | $sensors[$count][6] = "& | ||
+ | $color = " | ||
+ | } | ||
+ | elsif ($sensors[$count][5] < $sensors[$count][3]){ | ||
+ | print "IF: status for $sensors[$count][1] is yellow\n" | ||
+ | $sensors[$count][6] = "& | ||
+ | if ($color != " | ||
+ | $color = " | ||
+ | } | ||
+ | } | ||
+ | else { | ||
+ | print "IF: status for $sensors[$count][1] is green\n" | ||
+ | $sensors[$count][6] = "& | ||
+ | } | ||
+ | $sth-> | ||
+ | $count++; | ||
+ | } | ||
+ | |||
+ | # We can close the database now | ||
+ | $dbh-> | ||
+ | |||
+ | # Next is to get our results into an array | ||
+ | # For reference, 0=SerialNumber 1=name 2=description 3=min 4=max 5=value 6=color in our array | ||
+ | |||
+ | my $tmp = " | ||
+ | print $color if ($debug); | ||
+ | $count = 0; | ||
+ | while (@{sensors[$count]}) { | ||
+ | print " | ||
+ | print " | ||
+ | $tmp = $tmp." | ||
+ | $tmp = $tmp." | ||
+ | $tmp = $tmp." | ||
+ | $count++; | ||
+ | } | ||
+ | |||
+ | # Now we decode from UTF-8 to latin1 (iso-8859-1) if there is anything in utf8 open(TEMP, "> | ||
+ | print TEMP $tmp; close(TEMP); | ||
+ | |||
+ | # Now we get the converted data | ||
+ | $tmp = `/ | ||
+ | |||
+ | # Now finally we output the information to our beloved hobbit | ||
+ | my $date = localtime; | ||
+ | my $cmd = "$BB $BBDISP \" | ||
+ | system($cmd); | ||
+ | |||
+ | print $cmd if ($debug); | ||
+ | print $tmp if ($debug); | ||
+ | |||
+ | exit; | ||
+ | </ | ||
+ | |||
+ | Here is the output from this script:< | ||
+ | & | ||
+ | : min=1.000 max=25.000 | ||
+ | : This sensor has not yet been described | ||
+ | |||
+ | & | ||
+ | : min=0.000 max=99.999 | ||
+ | : This sensor has not yet been described | ||
+ | |||
+ | & | ||
+ | : min=14.000 max=25.000 | ||
+ | : This sensor has not yet been described | ||
+ | |||
+ | & | ||
+ | : min=0.000 max=99.999 | ||
+ | : This sensor has not yet been described | ||
+ | </ | ||
+ | |||
+ | rrd_digitemp.pl -- This script parses the information from hobbit and produces the channel data to make the RRD files.< | ||
+ | # | ||
+ | use strict; | ||
+ | |||
+ | # Input parameters: Hostname, testname (column), and messagefile | ||
+ | my $hostname=$ARGV[0]; | ||
+ | my $testname=$ARGV[1]; | ||
+ | my $fname=$ARGV[2]; | ||
+ | |||
+ | my ($line1, @line, @buff, @key, @value, $value, @tmp); | ||
+ | |||
+ | open(IN," | ||
+ | read(IN, $line1, 10000); | ||
+ | @line=split(' | ||
+ | @buff = grep(/ = /,@line); | ||
+ | close(IN); | ||
+ | chomp(@buff); | ||
+ | for( my $i = 0; $i < scalar(@buff); | ||
+ | { | ||
+ | $buff[$i] = substr($buff[$i], | ||
+ | $buff[$i] =~ s/ C//g; # Removing the end | ||
+ | $buff[$i] =~ s/ //g; # Removing all the whitespace | ||
+ | @tmp = split(' | ||
+ | $key[$i] = makesafe($tmp[0]); | ||
+ | $value[$i] = $tmp[1]; | ||
+ | # print $buff[$i]." | ||
+ | } | ||
+ | |||
+ | open(IN,">>/ | ||
+ | write($buff[1]); | ||
+ | close(IN); | ||
+ | |||
+ | # The next loop will print out the information for making the RRD file. | ||
+ | for( my $i = 0; $i < scalar(@key); | ||
+ | print " | ||
+ | # print " | ||
+ | print $testname." | ||
+ | print $value[$i]." | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | # This sub produces safe output so hobbit will be able to make the files | ||
+ | # (It seems that hobbit doesn' | ||
+ | sub makesafe { | ||
+ | my $word = shift; | ||
+ | $word =~ s/ö/o/g; | ||
+ | $word =~ s/á/a/g; | ||
+ | $word =~ s/í/i/g; | ||
+ | $word =~ s/é/e/g; | ||
+ | $word =~ s/ó/o/g; | ||
+ | $word =~ s/ý/y/g; | ||
+ | $word =~ s/ú/u/g; | ||
+ | $word =~ s/æ/ae/g; | ||
+ | $word =~ s/ð/d/g; | ||
+ | $word =~ s/þ/th/g; | ||
+ | # $word =~ s/_//g; | ||
+ | # $word = lc($word); | ||
+ | return $word; | ||
+ | } | ||
+ | |||
+ | exit; | ||
+ | </ | ||
+ |