root / plugins / spotweb / spotweb_cat_total @ 430d68ff
Historique | Voir | Annoter | Télécharger (3 ko)
| 1 |
#!/usr/bin/perl |
|---|---|
| 2 |
# |
| 3 |
# Munin plugin for total spot by categories in a spotweb MySQL database |
| 4 |
# |
| 5 |
# Copyright (C) 2011 - Rowdy Schwach?fer (http://rowdy.nl) |
| 6 |
# |
| 7 |
# Spotweb : http://github.com/spotweb/spotweb |
| 8 |
# |
| 9 |
# This program is free software: you can redistribute it and/or modify |
| 10 |
# it under the terms of the GNU General Public License as published by |
| 11 |
# the Free Software Foundation, either version 3 of the License, or |
| 12 |
# (at your option) any later version. |
| 13 |
# |
| 14 |
# This program is distributed in the hope that it will be useful, |
| 15 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
# GNU General Public License for more details. |
| 18 |
# |
| 19 |
# You should have received a copy of the GNU General Public License |
| 20 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 |
# |
| 22 |
# |
| 23 |
# Configuration example |
| 24 |
# |
| 25 |
# [spotweb*] |
| 26 |
# env.mysql /usr/bin/mysql # MySQL binary (optional) |
| 27 |
# env.mysqlopts -u <MYSQL_USERNAME> -p<MYSQL_PASSWORD> # How to connect to the database (optional if no password is set) |
| 28 |
# env.database spotweb # Spotweb database (optional) |
| 29 |
# |
| 30 |
# [spotweb_cat_total] |
| 31 |
# env.countporn 'yes' # Also count porn? |
| 32 |
# |
| 33 |
# |
| 34 |
|
| 35 |
use strict; |
| 36 |
|
| 37 |
# Environment variables |
| 38 |
my $MYSQL = $ENV{mysql} || "/usr/bin/mysql";
|
| 39 |
my $MYSQLOPTS = $ENV{mysqlopts} || "";
|
| 40 |
my $DATABASE = $ENV{database} || "spotweb";
|
| 41 |
my $COUNTPORN = $ENV{countporn} || "yes";
|
| 42 |
|
| 43 |
|
| 44 |
# Output for config |
| 45 |
if(defined $ARGV[0] && $ARGV[0] eq 'config') {
|
| 46 |
print <<EOC |
| 47 |
graph_title Spotweb spots by Category (Totals) |
| 48 |
graph_vlabel Spots |
| 49 |
graph_category spotweb |
| 50 |
cat0.label Videos/images |
| 51 |
cat0.colour 0f94e1 |
| 52 |
cat1.label Music |
| 53 |
cat1.colour efac26 |
| 54 |
cat2.label Games |
| 55 |
cat2.colour 1ae31a |
| 56 |
cat3.label Applications |
| 57 |
cat3.colour e33b1a |
| 58 |
EOC |
| 59 |
; |
| 60 |
exit 0; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
if($COUNTPORN eq 'yes') { &print_value(0); }
|
| 65 |
else {
|
| 66 |
# 11-04-2011 - Added the new pr0n filters |
| 67 |
# &print_value(0, " AND subcatd NOT LIKE '%23%' AND subcatd NOT LIKE '%24%' AND subcatd NOT LIKE '%25%' AND subcatd NOT LIKE '%26%'"); |
| 68 |
&print_value(0, " AND (subcatz IS NULL OR subcatz NOT LIKE '%z4%') AND subcatd NOT LIKE '%d23%' AND subcatd NOT LIKE '%d24%' AND subcatd NOT LIKE '%d25%' AND subcatd NOT LIKE '%d26%' AND subcatd NOT LIKE '%d72%' AND subcatd NOT LIKE '%d73%' AND subcatd NOT LIKE '%d74%' AND subcatd NOT LIKE '%d75%' AND subcatd NOT LIKE '%d76%' AND subcatd NOT LIKE '%d77%' AND subcatd NOT LIKE '%d78%' AND subcatd NOT LIKE '%d79%' AND subcatd NOT LIKE '%d80%' AND subcatd NOT LIKE '%d81%' AND subcatd NOT LIKE '%d82%' AND subcatd NOT LIKE '%d83%' AND subcatd NOT LIKE '%d84%' AND subcatd NOT LIKE '%d85%' AND subcatd NOT LIKE '%d86%' AND subcatd NOT LIKE '%d87%' AND subcatd NOT LIKE '%d88%' AND subcatd NOT LIKE '%d88%' AND subcatd NOT LIKE '%d89%'"); |
| 69 |
} |
| 70 |
&print_value(1); |
| 71 |
&print_value(2); |
| 72 |
&print_value(3); |
| 73 |
|
| 74 |
sub print_value {
|
| 75 |
my $spots = `$MYSQL $MYSQLOPTS -e "SELECT count(*) as spots FROM $DATABASE.spots WHERE category = $_[0]$_[1];"`; |
| 76 |
$spots =~ /(\d+)/; |
| 77 |
print "cat".$_[0].".value ".$1."\n"; |
| 78 |
} |
