Projet

Général

Profil

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

root / plugins / reddit_karma / reddit_karma_ @ 5177d105

Historique | Voir | Annoter | Télécharger (1,94 ko)

1
#!/bin/bash
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
    # No real requirements.
35
    echo yes
36
    exit 0
37
fi
38

    
39
##
40
# config
41
##
42
if [ "$1" = "config" ]; then
43
    echo "graph_title Reddit Karma for $reddit_user"
44
    echo 'graph_vlabel karma'
45
    echo 'graph_args --base 1000'
46
    echo 'graph_scale no'
47
    echo 'graph_vlabel Link Karma'
48
    echo 'graph_category misc'
49
    echo 'comment_karma.label Comment Karma'
50
    echo 'comment_karma.draw LINE'
51
    echo 'link_karma.label Link Karma'
52
    echo 'link_karma.draw LINE'
53
    exit 0
54
fi
55

    
56
##
57
# Main
58
##
59
# Get current karma stats.
60
link_karma=$(curl -s http://www.reddit.com/user/${reddit_user}/about.json | grep -Eo 'link_karma": [0-9]+' | cut -d' ' -f2)
61
comment_karma=$(curl -s http://www.reddit.com/user/${reddit_user}/about.json | grep -Eo 'comment_karma": [0-9]+' | cut -d' ' -f2)
62

    
63
# Output karma stats.
64
echo "link_karma.value $link_karma"
65
echo "comment_karma.value $comment_karma"