TIPS & TRICKS

Splunk2LCD : Display your Alerts on an LCD

This morning I got a nice little LCD from Crystalfontz that allows me to connect to it via the open source project lcdproc. After a bit of compiling and installing, LCDproc (which runs natively on linux, darwin (osx) and most other unix distros) connects to any serial, parallel or USB LCD device. In this case, the Crystalfontz LCD is 4 line by 20 character display.

Splunk2LCD

Once configured and connected, you start the server and accept connections.

I then grabbed the IO-LCDproc perl module and modified it to display to the LCDproc server. You can get the IO-LCDproc through CPAN.

Here is the code that would go in your $SPLUNK_HOME/bin/scripts directory

#!/use/bin/perl -w
use IO::LCDproc;
use IO::Socket;
use strict;

&usage if (! $ARGV[0]);

my $client = IO::LCDproc::Client->new(host => “localhost”, name => “MYNAME”, port => “13666”);

my $screen = IO::LCDproc::Screen->new(name => “screen”);

my $title = IO::LCDproc::Widget->new( name => “date”, type => “title”);

my $first = IO::LCDproc::Widget->new(
name => “first”, align => “center”, type => “string”, xPos => 1, yPos => 2,
data => “test”);
my $second = IO::LCDproc::Widget->new(
name => “second”, align => “center”, type => “string”, xPos => 1, yPos => 3
);
my $third = IO::LCDproc::Widget->new(
name => “third”, align => “center”, type => “string”, xPos => 1, yPos => 4
);

$client->add ( $screen );
$screen->add ( $title, $first, $second, $third );
$client->connect() or die “Cannot Connect: $!”;
$client->initialize();

$title->set( data => “Splunk2LCD” );
$first->set( data => “$ARGV[1]” );
$second->set( data => “$ARGV[4]” );
$third->set( data => “$ARGV[5]” );

sleep 5;
exit 1;

sub usage {
print <<USAGE;
LCDproc Client for Splunk
Mark Cohen
Usage: ./splunk2lcd2.pl ARGV0 ARGV1 ARGV2
USAGE
exit 1;
}

By Mark Cohen

Splunk
Posted by

Splunk

Join the Discussion