Projet

Général

Profil

Révision e55f0fc7

IDe55f0fc7c8af2a52959cb7fe97359255750b80a0
Parent 5d1473e9
Enfant 8308ba95

Ajouté par Rowdy Schwach?fer il y a presque 14 ans

Initial version

Voir les différences:

plugins/other/spotweb_cat_total
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
#
24
### Configuration example
25
#
26
# [spotweb*]
27
# env.mysql /usr/bin/mysql                               # MySQL binary (optional)
28
# env.mysqlopts -u <MYSQL_USERNAME> -p<MYSQL_PASSWORD>   # How to connect to the database (optional if no password is set)
29
# env.database spotweb                                   # Spotweb database (optional)
30
#
31
# [spotweb_cat_total]
32
# env.countporn = 'no'									 # Also count porn? Default is 'yes'
33
#
34
#
35

  
36
use strict;
37

  
38
# Environment variables
39
my $MYSQL 		= $ENV{mysql} || "/usr/bin/mysql";
40
my $MYSQLOPTS 	= $ENV{mysqlopts} || "";
41
my $DATABASE 	= $ENV{database} || "spotweb";
42
my $COUNTPORN 	= $ENV{countporn} || "yes";
43

  
44

  
45
# Output for config
46
if(defined $ARGV[0] && $ARGV[0] eq 'config') {
47
print <<EOC
48
graph_title Spotweb spots by Category (Totals)
49
graph_vlabel Spots
50
graph_category spotweb
51
cat0.label Videos/images
52
cat1.label Music
53
cat2.label Games
54
cat3.label Applications
55
EOC
56
;
57
exit 0;
58
}
59

  
60

  
61
# Output of values. We just call a subroutine here to prevent much duplicate code
62
if($COUNTPORN eq 'yes') { 
63
    &print_value(0);
64
}
65
else { 
66
    &print_value(0, " AND subcatd NOT LIKE '%23%' AND subcatd NOT LIKE '%24%' AND subcatd NOT LIKE '%25%' AND subcatd NOT LIKE '%26%'"); 
67
}
68
&print_value(1);
69
&print_value(2);
70
&print_value(3);
71

  
72

  
73
# Subroutine to print the values
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
}

Formats disponibles : Unified diff