2012-07-23 14:33:01 +02:00
|
|
|
#!/bin/sh
|
2012-07-20 20:44:18 +02:00
|
|
|
##########################
|
|
|
|
# reddit_karma_
|
|
|
|
##########################
|
|
|
|
# Munin Plugin to track the karma activity of a Reddit user.
|
|
|
|
#
|
|
|
|
# Copyright 2012 Mark Caudill <mark AT caudill DOT me>
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
# Usage:
|
|
|
|
# Create symbolic link from /etc/munin/plugins/reddit_karma_your_username
|
|
|
|
# to /usr/share/munin/plugins/reddit_karma_
|
|
|
|
#
|
|
|
|
|
|
|
|
# Get the Reddit username by parsing this scripts filename.
|
|
|
|
reddit_user=${0##*reddit_karma_}
|
|
|
|
|
|
|
|
##
|
|
|
|
# autoconf
|
|
|
|
##
|
|
|
|
if [ "$1" = "autoconf" ]; then
|
2012-07-21 15:33:17 +02:00
|
|
|
# Check that curl is installed
|
2017-07-01 15:51:37 +02:00
|
|
|
if command -v curl >/dev/null 2>&1; then
|
2012-07-21 15:33:17 +02:00
|
|
|
echo "yes"
|
|
|
|
else
|
|
|
|
echo "no (no curl installed)"
|
|
|
|
fi
|
2012-07-20 20:44:18 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
##
|
|
|
|
# config
|
|
|
|
##
|
|
|
|
if [ "$1" = "config" ]; then
|
|
|
|
echo "graph_title Reddit Karma for $reddit_user"
|
|
|
|
echo 'graph_vlabel karma'
|
|
|
|
echo 'graph_args --base 1000'
|
|
|
|
echo 'graph_scale no'
|
|
|
|
echo 'graph_vlabel Link Karma'
|
2017-02-23 23:12:19 +01:00
|
|
|
echo 'graph_category other'
|
2012-07-20 20:44:18 +02:00
|
|
|
echo 'comment_karma.label Comment Karma'
|
|
|
|
echo 'comment_karma.draw LINE'
|
|
|
|
echo 'link_karma.label Link Karma'
|
|
|
|
echo 'link_karma.draw LINE'
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
##
|
|
|
|
# Main
|
|
|
|
##
|
|
|
|
# Get current karma stats.
|
2018-03-08 02:46:47 +01:00
|
|
|
about_user_url="http://www.reddit.com/user/${reddit_user}/about.json"
|
|
|
|
link_karma=$(curl -s "$about_user_url" | grep -Eo 'link_karma": [0-9]+' | cut -d' ' -f2)
|
|
|
|
comment_karma=$(curl -s "$about_user_url" | grep -Eo 'comment_karma": [0-9]+' | cut -d' ' -f2)
|
2012-07-20 20:44:18 +02:00
|
|
|
|
|
|
|
# Output karma stats.
|
|
|
|
echo "link_karma.value $link_karma"
|
|
|
|
echo "comment_karma.value $comment_karma"
|