To get output to an LCD display 1-wire can be used. This article will describe how to that and include an example to get status from Nagios or op5 Monitor on the display.
I use it to get a quick overview how my DataCenter is doing. When the LCD display is flashing something has either WARNING or CRITICAL status.
Step by step guide
1. Get the Hardware, I bought it from http://shop.temperatur.nu.
LCD controller http://shop.temperatur.nu/1wire-lcd-kontroller-p-74.html
LCD Display http://shop.temperatur.nu/hd44780-20×4-character-lcd-display-bla-bakgrundsbelysning-p-75.html
2. Make sure that your 1-wire bus works
Read my earlier articles
3. Send a text to the LCD Display
echo “Test” > /1-wire/FF.A30300000100/line20.0
If you get text on your LCD everything works
4. Use the script below as a template to get Nagios or op5 Monitor data to your LCD display. It is a modified nagios2lcd perl script.
I have put it in /etc/rc.local so it starts everytime my machine boots.
#!/usr/bin/perl # +----------------------------------------------------------------------------+ # | StackSys | # | ron.sweeney@gmail.com | # | http://www.stacksys.com |
# |----------------------------------------------------------------------------|
# | Modified by peter@it-slav.net
# | http://www.it-slav.net/blogs/
# |----------------------------------------------------------------------------|
# | FILE : nagios2lcd.pl |
# | CLASS : Toys |
# | PURPOSE : Show nagios status on an lcdproc server. |
# | USAGE : ./nagios2lcd.pl server port interval |
# | NOTE : This script runs on versions 2.0 of Nagios (Tested on 2.01b) |
# | RESOURCE : Nagios(http://www.nagios.org) LCDPROC(http://www.lcdproc.org/)|
# +----------------------------------------------------------------------------+
#&usage if (! $ARGV[0]);
use OW;
my $owserver = "127.0.0.1:3001";
unless(OW::init($owserver)) {
$status = $ERRORS{CRIT};
$message = "OWServer not running at $owserver\n";
exit $status;
}
while (true) {
&message;
}
sub message {
#@nagios = `/usr/local/nagios/bin/nagiostats`;
@nagios = `/opt/monitor/bin/nagiostats`;
foreach $line (@nagios) {
if ($line =~m/Hosts Up\/Down\/Unreach/ ) {
@hosts = split(/ +/, $line);
@hostsvalues = split(/\//, $hosts[1]);
$hostup = $hostsvalues[0];
$hostdown = $hostsvalues[1];
$hostunreach = $hostsvalues[2];
$hostup =~s/ //g;
$hostdown =~s/ //g;
$hostunreach =~s/ //g;
chop($hostunreach);
}
elsif ($line =~m/Services Ok\/Warn\/Unk\/Crit/ ) {
@services = split(/ +/, $line);
@servicevalues = split(/\//, $services[1]);
$serviceok = $servicevalues[0];
$servicewarn = $servicevalues[1];
$serviceunk = $servicevalues[2];
$servicecrit = $servicevalues[3];
$serviceok =~s/ //g;
$servicewarn =~s/ //g;
$serviceunk =~s/ //g;
$servicecrit =~s/ //g;
chop($servicecrit);
}
elsif ($line =~m/Status File Age:/ ) {
@version = split(/ +/, $line);
#@versionvalues = split(/ +/, $version[1]);
$nagiosversion = $version[1];
chop($nagiosversion);
}
}
#Get indoor and outdoor temperatures
$tempinne = OW::get('10.04E060010800/temperature');
$tempinne =~ s/^\s*(.*?)\s*$/$1/;
$tempinne = sprintf("%.2f", $tempinne);
$tempute = OW::get('10.DEF05F010800/temperature');
$tempute =~ s/^\s*(.*?)\s*$/$1/;
$tempute = sprintf("%.2f", $tempute);
$datum=`/bin/date`;
OW::put('FF.A30300000100/line20.0','Temperatur');
OW::put('FF.A30300000100/line20.1',"PDC: $tempinne\xdfC");
OW::put('FF.A30300000100/line20.2',"Outdoor: $tempute\xdfC");
#OW::put('FF.A30300000100/line20.3',"$datum");
for ($i=1;$i<5;$i++) {
$datum=`/bin/date`;
OW::put('FF.A30300000100/line20.3',"$datum");
sleep (1);
}
my $gar="N/A";
OW::put('FF.A30300000100/line20.0'," ");
OW::put('FF.A30300000100/line20.1'," It-Slav.net");
OW::put('FF.A30300000100/line20.2'," ");
#OW::put('FF.A30300000100/line20.3'," ");
for ($i=1;$i<5;$i++) {
$datum=`/bin/date`;
OW::put('FF.A30300000100/line20.3',"$datum");
sleep (1);
}
#sleep(3);
#If any problem, flash the display
if ($hostdown!=0||$hostunreach>=1||$servicewarn!=0||$servicecrit>=1||$serviceunk>=1) {
$blink=1;
}
else {
$blink=0;
}
OW::put('FF.A30300000100/line20.0','Op5 Monitor Status');
OW::put('FF.A30300000100/line20.1',"Host:U-$hostup D-$hostdown U-$hostunreach");
OW::put('FF.A30300000100/line20.2',"Serv:O-$serviceok W-$servicewarn ");
if ($servicecrit==0) {
OW::put('FF.A30300000100/line20.3'," C-$servicecrit U-$serviceunk");
} else {
OW::put('FF.A30300000100/line20.3'," C-$servicecrit U-$serviceunk");
}
for($i=0;$i<=50;$i++) {
if ($blink==1) {
OW::put('FF.A30300000100/backlight','0');
}
OW::put('FF.A30300000100/backlight','1');
}
}
Leave a Reply
You must be logged in to post a comment.




