Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / reddit_karma / reddit_karma_ @ e3899a30

Historique | Voir | Annoter | Télécharger (2,04 ko)

1 735520ad Steve Schnepp
#!/bin/sh
2 5177d105 Mark Caudill
##########################
3
# reddit_karma_
4
##########################
5
# Munin Plugin to track the karma activity of a Reddit user.
6
# 
7
# Copyright 2012 Mark Caudill <mark AT caudill DOT me>
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
# Usage:
23
# Create symbolic link from /etc/munin/plugins/reddit_karma_your_username
24
# to /usr/share/munin/plugins/reddit_karma_
25
#
26
27
# Get the Reddit username by parsing this scripts filename.
28
reddit_user=${0##*reddit_karma_}
29
30
##
31
# autoconf
32
##
33
if [ "$1" = "autoconf" ]; then
34 067e4c8b Mark Caudill
    # Check that curl is installed
35
    if hash curl &>/dev/null; then
36
        echo "yes"
37
    else
38
        echo "no (no curl installed)"
39
    fi
40 5177d105 Mark Caudill
    exit 0
41
fi
42
43
##
44
# config
45
##
46
if [ "$1" = "config" ]; then
47
    echo "graph_title Reddit Karma for $reddit_user"
48
    echo 'graph_vlabel karma'
49
    echo 'graph_args --base 1000'
50
    echo 'graph_scale no'
51
    echo 'graph_vlabel Link Karma'
52 e3899a30 Gabriele Pohl
    echo 'graph_category Reddit'
53 5177d105 Mark Caudill
    echo 'comment_karma.label Comment Karma'
54
    echo 'comment_karma.draw LINE'
55
    echo 'link_karma.label Link Karma'
56
    echo 'link_karma.draw LINE'
57
    exit 0
58
fi
59
60
##
61
# Main
62
##
63
# Get current karma stats.
64
link_karma=$(curl -s http://www.reddit.com/user/${reddit_user}/about.json | grep -Eo 'link_karma": [0-9]+' | cut -d' ' -f2)
65
comment_karma=$(curl -s http://www.reddit.com/user/${reddit_user}/about.json | grep -Eo 'comment_karma": [0-9]+' | cut -d' ' -f2)
66
67
# Output karma stats.
68
echo "link_karma.value $link_karma"
69
echo "comment_karma.value $comment_karma"