Projet

Général

Profil

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

root / plugins / reddit_karma / reddit_karma_ @ 33e95e6f

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

1
#!/bin/sh
2
##########################
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
    # Check that curl is installed
35
    if command -v curl >/dev/null 2>&1; then
36
        echo "yes"
37
    else
38
        echo "no (no curl installed)"
39
    fi
40
    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
    echo 'graph_category forum'
53
    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
about_user_url="http://www.reddit.com/user/${reddit_user}/about.json"
65
link_karma=$(curl -s "$about_user_url" | grep -Eo 'link_karma": [0-9]+' | cut -d' ' -f2)
66
comment_karma=$(curl -s "$about_user_url" | grep -Eo 'comment_karma": [0-9]+' | cut -d' ' -f2)
67

    
68
# Output karma stats.
69
echo "link_karma.value $link_karma"
70
echo "comment_karma.value $comment_karma"