- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
#!/usr/bin/python
# encoding utf8
# head1 NAME
#
# wordpress_plugin_ - Munin plugin to display wordpress download stats for plugins.
#
# CONFIGURATION
#
# This script is used to generate data for the number of downloads of plugins
#
# APPLICABLE SYSTEMS
#
# Any system that can connect to wordpress plugins
#
# CONFIGURATION
#
# This script is used to generate data for several graphs. To generate data for
# one specific wordpress plugin instance, you need to create a symbolic link
# with a name like wordpress_plugin_download_counter_<NAME> to this script.
#
# For example: to track the WP Super Cache number of downloads
#
# The URL for it is http://wordpress.org/plugins/wp-super-cache/
# So you would use the following --------------> ^^^^^^^^^^^^^^
# wp-super-cache as the name
#
# i.e.
#
# cd /etc/munin/plugins
# ln -s /usr/share/munin/plugins/wordpress_plugin_download_counter_ wordpress_plugin_download_counter_wp-super-cache
# /etc/init.d/munin-node restart
#
import sys, os, string, urllib2
from urllib2 import HTTPError
import socket
THIS_SCRIPT_NAME = "wordpress_plugin_download_counter_"
THIS_TO_BE_FOUND = "UserDownloads"
def get_stats(stat_url):
contents=""
try:
socket.setdefaulttimeout(10)
response = urllib2.urlopen(stat_url)
contents = response.read()
except HTTPError, e:
sys.exit()
start_index_of_download = string.find(contents, THIS_TO_BE_FOUND) + len(THIS_TO_BE_FOUND) + 1
end_index_of_download = string.find(contents, "\"", start_index_of_download)
print("DOWNLOADS.value " + (contents[start_index_of_download: end_index_of_download]))
if __name__ == "__main__":
# figure out which one we are doing
full_caller_name = sys.argv[0]
index_of_wordpress = full_caller_name.find(THIS_SCRIPT_NAME)
caller = sys.argv[0][len(THIS_SCRIPT_NAME) + index_of_wordpress:]
caller_nice_name = caller.replace("_", " ")
caller_nice_name = caller_nice_name.replace("-", " ")
# are we doing config/autoconfig?
if(len(sys.argv) > 1):
if (sys.argv[1]=="config"):
print "graph_title Plugin Downloads for '" + caller_nice_name.title() + "'"
print "graph_vlabel Number Of Downloads"
print "graph_category wordpress"
print "graph_order DOWNLOADS"
# in green
print "DOWNLOADS.label Downloads"
print "DOWNLOADS.colour 00cc00"
print "DOWNLOADS.draw AREA"
print "graph_args --base 1000 -l 0 "
print "graph_scale no "
sys.exit()
# now that we know the caller, get the environment
stat_url = "http://wordpress.org/extend/plugins/" + caller_nice_name + "/"
if(None != stat_url):
get_stats(stat_url)
Комментарии (0) RSS
Добавить комментарий