1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-22 22:25:23 +00:00

tidied up the code abit. now perl strict safe

This commit is contained in:
ian dobson 2010-10-17 16:48:15 +02:00 committed by Steve Schnepp
parent 62c26c4a52
commit 1c9538f5df

View file

@ -1,29 +1,27 @@
#!/usr/bin/perl -w
#
# Munin plugin for MythTV
# This plugin can graph:- EPG programs per channels
# This plugin can graph:- EPG programs per channel
#
# NOTE: This plugin needs to run as root so add the following to your munin-node config file
# [mythtv_status*]
# user=root
# The http/xml status page must be enabled in the mythtv backend.
#
# $Log$
# Revision 0.1 2008/03/27 idobson
# Code for all options except recorded implemented
#
# Revision 0.2 2010/10/07 idobson
# Fixed up autoconf option, it actually checks if MythTV/mysql Database options are configured
# Code now strict safe, cleaned up the sql queries
#
# Magic markers (optional - used by munin-config and installation scripts):
#
#%# family=auto
#%# capabilities=autoconf
use LWP::Simple;
#use XML::Parser;
use strict;
use warnings;
use DBI;
# Parameters for Backend xml feed
my $backendHostname = "192.168.0.2";
my $backendStatusPort = "6544";
# SQL parameters are read from mysql.txt
# There should be no need to change anything after this point
my $SQLServer = "";
@ -31,33 +29,43 @@ my $SQLUser = "";
my $SQLPassword = "";
my $SQLDBName = "";
my @result="";
my $result="";
my $gata="";
my $VideoInput=1;
my $Channel="";
#Auto config options
if ($ARGV[0] and $ARGV[0] eq "autoconf" ) {
print "yes\n";
exit 0;
}
#Setup SQL access
PrepSQLRead();
#Auto config options
if ($ARGV[0] and $ARGV[0] eq "autoconf" ) {
if ( $SQLDBName ne "" ) {
print "yes\n";
exit 0;
} else {
print "no\n";
print "cannot find MythTV configuration file my.txt\n";
exit 1;
}
}
#Config Options
##Configuration for encoder, no config data needs to read from anywhere
if ($ARGV[0] and $ARGV[0] eq "config"){
print "graph_scale off\n";
print "graph_title MythTV EPG per channel\n";
print "graph_args --base 1000\n";
print "graph_args --base 1000 --upper-limit 12 --lower-limit 0 --rigid\n";
print "graph_category MythTV\n";
print "graph_vlabel EPG days\n";
@result=SQLQuery("SELECT `chanid` , `name` FROM `channel` order by `chanid` ");
@result=SQLQuery("SELECT `chanid` , `name` FROM `channel` WHERE `visible` = '1' order by `chanid` ");
my $Ptr=0;
foreach $gata (@result) {
if ($Ptr == 0) {
$Channel = $gata;
print "Channel" . $Channel . "EPG.draw LINE1\n";
print "Channel" . $Channel . "EPG.min -1\n";
print "Channel" . $Channel . "EPG.max 12\n";
$Ptr=1;
} else {
print "Channel" . $Channel . "EPG.label EPG days for channel $gata\n";
@ -67,20 +75,24 @@ my $Channel="";
exit 0;
}
#Actually dump data to Munin
@result=SQLQuery("SELECT c.chanid, (UNIX_TIMESTAMP(MAX(c.starttime))
- UNIX_TIMESTAMP(NOW()))/86400 AS calc
FROM program c, channel o
WHERE o.chanid = c.chanid GROUP BY o.chanid
ORDER BY calc ");
@result=SQLQuery("SELECT o.chanid, (UNIX_TIMESTAMP(MAX(c.endtime))
- UNIX_TIMESTAMP(NOW()))/86400
FROM channel o, program c
WHERE o.chanid = c.chanid
AND o.visible = '1'
GROUP BY o.chanid");
my $Ptr=0;
foreach $gata (@result) {
if ($Ptr == 0) {
$Channel = $gata;
$Ptr=1;
} else {
print "Channel" . $Channel . "EPG.value $gata\n";
if ( $gata > 12 ) {
print "Channel" . $Channel . "EPG.value 12.0\n";
} else {
print "Channel" . $Channel . "EPG.value $gata\n";
}
$Ptr=0;
}
}
@ -99,7 +111,6 @@ sub PrepSQLRead {
'/usr/share/mythtv/mysql.txt',
'/etc/mythtv/mysql.txt',
'/usr/local/etc/mythtv/mysql.txt',
"$ENV{HOME}/.mythtv/mysql.txt",
'mysql.txt'
);
foreach my $file (@mysql) {
@ -141,6 +152,7 @@ sub PrepSQLRead {
sub SQLQuery {
my ($QUERY) = @_;
my @data;
my $ref;
my $dbh = DBI->connect("DBI:mysql:$SQLDBName:$SQLServer", $SQLUser, $SQLPassword)
or die "Couldn't connect to database: " . DBI->errstr;
my $table_data = $dbh->prepare($QUERY) or die "Couldn't prepare statement: " . $dbh->errstr;