mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-23 06:35:42 +00:00
tidied up the code abit. now perl strict safe
This commit is contained in:
parent
62c26c4a52
commit
1c9538f5df
1 changed files with 37 additions and 25 deletions
|
@ -1,29 +1,27 @@
|
||||||
#!/usr/bin/perl -w
|
#!/usr/bin/perl -w
|
||||||
#
|
#
|
||||||
# Munin plugin for MythTV
|
# 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
|
# NOTE: This plugin needs to run as root so add the following to your munin-node config file
|
||||||
# [mythtv_status*]
|
# [mythtv_status*]
|
||||||
# user=root
|
# user=root
|
||||||
# The http/xml status page must be enabled in the mythtv backend.
|
|
||||||
#
|
#
|
||||||
# $Log$
|
# $Log$
|
||||||
# Revision 0.1 2008/03/27 idobson
|
# 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):
|
# Magic markers (optional - used by munin-config and installation scripts):
|
||||||
#
|
#
|
||||||
#%# family=auto
|
#%# family=auto
|
||||||
#%# capabilities=autoconf
|
#%# capabilities=autoconf
|
||||||
use LWP::Simple;
|
use strict;
|
||||||
#use XML::Parser;
|
use warnings;
|
||||||
use DBI;
|
use DBI;
|
||||||
|
|
||||||
# Parameters for Backend xml feed
|
|
||||||
my $backendHostname = "192.168.0.2";
|
|
||||||
my $backendStatusPort = "6544";
|
|
||||||
|
|
||||||
# SQL parameters are read from mysql.txt
|
# SQL parameters are read from mysql.txt
|
||||||
# There should be no need to change anything after this point
|
# There should be no need to change anything after this point
|
||||||
my $SQLServer = "";
|
my $SQLServer = "";
|
||||||
|
@ -31,33 +29,43 @@ my $SQLUser = "";
|
||||||
my $SQLPassword = "";
|
my $SQLPassword = "";
|
||||||
my $SQLDBName = "";
|
my $SQLDBName = "";
|
||||||
|
|
||||||
|
my @result="";
|
||||||
my $result="";
|
my $result="";
|
||||||
my $gata="";
|
my $gata="";
|
||||||
my $VideoInput=1;
|
my $VideoInput=1;
|
||||||
my $Channel="";
|
my $Channel="";
|
||||||
|
|
||||||
#Auto config options
|
|
||||||
if ($ARGV[0] and $ARGV[0] eq "autoconf" ) {
|
|
||||||
print "yes\n";
|
|
||||||
exit 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#Setup SQL access
|
#Setup SQL access
|
||||||
PrepSQLRead();
|
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
|
#Config Options
|
||||||
##Configuration for encoder, no config data needs to read from anywhere
|
##Configuration for encoder, no config data needs to read from anywhere
|
||||||
if ($ARGV[0] and $ARGV[0] eq "config"){
|
if ($ARGV[0] and $ARGV[0] eq "config"){
|
||||||
print "graph_scale off\n";
|
print "graph_scale off\n";
|
||||||
print "graph_title MythTV EPG per channel\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_category MythTV\n";
|
||||||
print "graph_vlabel EPG days\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;
|
my $Ptr=0;
|
||||||
foreach $gata (@result) {
|
foreach $gata (@result) {
|
||||||
if ($Ptr == 0) {
|
if ($Ptr == 0) {
|
||||||
$Channel = $gata;
|
$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;
|
$Ptr=1;
|
||||||
} else {
|
} else {
|
||||||
print "Channel" . $Channel . "EPG.label EPG days for channel $gata\n";
|
print "Channel" . $Channel . "EPG.label EPG days for channel $gata\n";
|
||||||
|
@ -67,20 +75,24 @@ my $Channel="";
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#Actually dump data to Munin
|
#Actually dump data to Munin
|
||||||
@result=SQLQuery("SELECT c.chanid, (UNIX_TIMESTAMP(MAX(c.starttime))
|
@result=SQLQuery("SELECT o.chanid, (UNIX_TIMESTAMP(MAX(c.endtime))
|
||||||
- UNIX_TIMESTAMP(NOW()))/86400 AS calc
|
- UNIX_TIMESTAMP(NOW()))/86400
|
||||||
FROM program c, channel o
|
FROM channel o, program c
|
||||||
WHERE o.chanid = c.chanid GROUP BY o.chanid
|
WHERE o.chanid = c.chanid
|
||||||
ORDER BY calc ");
|
AND o.visible = '1'
|
||||||
|
GROUP BY o.chanid");
|
||||||
my $Ptr=0;
|
my $Ptr=0;
|
||||||
foreach $gata (@result) {
|
foreach $gata (@result) {
|
||||||
if ($Ptr == 0) {
|
if ($Ptr == 0) {
|
||||||
$Channel = $gata;
|
$Channel = $gata;
|
||||||
$Ptr=1;
|
$Ptr=1;
|
||||||
} else {
|
} 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;
|
$Ptr=0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,7 +111,6 @@ sub PrepSQLRead {
|
||||||
'/usr/share/mythtv/mysql.txt',
|
'/usr/share/mythtv/mysql.txt',
|
||||||
'/etc/mythtv/mysql.txt',
|
'/etc/mythtv/mysql.txt',
|
||||||
'/usr/local/etc/mythtv/mysql.txt',
|
'/usr/local/etc/mythtv/mysql.txt',
|
||||||
"$ENV{HOME}/.mythtv/mysql.txt",
|
|
||||||
'mysql.txt'
|
'mysql.txt'
|
||||||
);
|
);
|
||||||
foreach my $file (@mysql) {
|
foreach my $file (@mysql) {
|
||||||
|
@ -141,6 +152,7 @@ sub PrepSQLRead {
|
||||||
sub SQLQuery {
|
sub SQLQuery {
|
||||||
my ($QUERY) = @_;
|
my ($QUERY) = @_;
|
||||||
my @data;
|
my @data;
|
||||||
|
my $ref;
|
||||||
my $dbh = DBI->connect("DBI:mysql:$SQLDBName:$SQLServer", $SQLUser, $SQLPassword)
|
my $dbh = DBI->connect("DBI:mysql:$SQLDBName:$SQLServer", $SQLUser, $SQLPassword)
|
||||||
or die "Couldn't connect to database: " . DBI->errstr;
|
or die "Couldn't connect to database: " . DBI->errstr;
|
||||||
my $table_data = $dbh->prepare($QUERY) or die "Couldn't prepare statement: " . $dbh->errstr;
|
my $table_data = $dbh->prepare($QUERY) or die "Couldn't prepare statement: " . $dbh->errstr;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue