From 5177d1054eaa5ec3d9152a66df3611f7c74083f5 Mon Sep 17 00:00:00 2001 From: Mark Caudill Date: Fri, 20 Jul 2012 18:44:18 +0000 Subject: [PATCH 1/2] Add plugin to track Reddit karma. --- plugins/reddit_karma/reddit_karma_ | 65 ++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100755 plugins/reddit_karma/reddit_karma_ diff --git a/plugins/reddit_karma/reddit_karma_ b/plugins/reddit_karma/reddit_karma_ new file mode 100755 index 00000000..9ff4cb16 --- /dev/null +++ b/plugins/reddit_karma/reddit_karma_ @@ -0,0 +1,65 @@ +#!/bin/bash +########################## +# reddit_karma_ +########################## +# Munin Plugin to track the karma activity of a Reddit user. +# +# Copyright 2012 Mark Caudill +# +# 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 . +# +# 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 + # No real requirements. + echo yes + 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' + echo 'graph_category misc' + 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. +link_karma=$(curl -s http://www.reddit.com/user/${reddit_user}/about.json | grep -Eo 'link_karma": [0-9]+' | cut -d' ' -f2) +comment_karma=$(curl -s http://www.reddit.com/user/${reddit_user}/about.json | grep -Eo 'comment_karma": [0-9]+' | cut -d' ' -f2) + +# Output karma stats. +echo "link_karma.value $link_karma" +echo "comment_karma.value $comment_karma" From 067e4c8b888d36baafcd092ce6d47a1a930cca5b Mon Sep 17 00:00:00 2001 From: Mark Caudill Date: Sat, 21 Jul 2012 13:33:17 +0000 Subject: [PATCH 2/2] Add check for curl during autoconf. --- plugins/reddit_karma/reddit_karma_ | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/reddit_karma/reddit_karma_ b/plugins/reddit_karma/reddit_karma_ index 9ff4cb16..535d6f3a 100755 --- a/plugins/reddit_karma/reddit_karma_ +++ b/plugins/reddit_karma/reddit_karma_ @@ -31,8 +31,12 @@ reddit_user=${0##*reddit_karma_} # autoconf ## if [ "$1" = "autoconf" ]; then - # No real requirements. - echo yes + # Check that curl is installed + if hash curl &>/dev/null; then + echo "yes" + else + echo "no (no curl installed)" + fi exit 0 fi