Projet

Général

Profil

Révision 604b9249

ID604b9249c8ff89f5519cfe0c15ca8718c0561183
Parent 46d1dcc9
Enfant 463bf9cc

Ajouté par Patschi il y a plus de 12 ans

Create wordpress2

Voir les différences:

plugins/other/wordpress2
1
#!/usr/bin/php
2
<?php
3
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
4
/*
5
 ** REQUIRES PHP5-CLI **
6
 ---- DESCRIPTION ----
7
 wordpress plugin for munin
8
  it's a simple plugin to monitor users, comments, pingbacks
9
  and your posts from your wordpress homepage.
10

  
11
  Simply put your path of wp-config.php in your munin-node 
12
  configuration and this plugin does the rest for you.
13
  Happy monitoring! :)
14

  
15
  This plugin was inspired by the existing wordpress plugin in bash/sh:
16
   https://github.com/munin-monitoring/contrib/blob/master/plugins/other/wordpress
17

  
18

  
19
 ---- CONFIGURATION ----
20
 You just need to provide the path to your
21
 wp-config.php of your wordpress installation.
22
 
23
 The configuration for munin-node is by default
24
 at: /etc/munin/plugin-conf.d/munin-node
25

  
26
 Example configuration:
27
 [wordpress]
28
 env.NAME Blog of Chuck Norris
29
 env.CONF /var/www/wordpress/wp-config.php
30

  
31
 or you can use:
32

  
33
 [wordpress]
34
 env.NAME Blog of Chuck Norris
35
 env.HOST 127.0.0.1
36
 env.USER blog
37
 env.PASS password
38
 env.DBNM wordpress
39
 env.TBPF wp_
40

  
41

  
42
 ---- More details ----
43
 @Author...: Patrik Kernstock
44
 @Version..: v1.1
45
 @Date.....: 26 November 2012
46
 @Web......: http://pkern.at
47
 @Support..: support@pkern.at
48
 @GitHub...: https://github.com/patschi/munin-plugins
49
 @License..: http://creativecommons.org/licenses/by-nc-sa/3.0/
50

  
51
*/
52
#%# family=auto
53
#%# capabilities=autoconf
54

  
55
// Get configuration variables
56
$d["name"] = getenv("NAME");
57
$d["conf"] = getenv("CONF");
58
$d["host"] = getenv("HOST");
59
$d["user"] = getenv("USER");
60
$d["pass"] = getenv("PASS");
61
$d["tbpf"] = getenv("TBPF");
62
$d["dbnm"] = getenv("DBNM");
63

  
64
if(!empty($d["conf"]) && !empty($d["name"])) {
65
  // INCLUDE wp-config.php
66
	define("ABSPATH", str_replace("wp-config.php", "", $d["conf"]));
67
	require_once($d["conf"]);
68
	$d["host"] = DB_HOST;
69
	$d["user"] = DB_USER;
70
	$d["pass"] = DB_PASSWORD;
71
	$d["dbnm"] = DB_NAME;
72
	$d["tbpf"] = $table_prefix;
73
}
74

  
75
// In which category it should be displayed
76
$category = "other";
77

  
78
if($argv[1] == "config") {
79
	echo 'graph_title wordpress statistic of '.$d["name"]."\n";
80
	echo 'graph_order users posts comments pingbacks'."\n";
81
	echo 'graph_vlabel Wordpress'."\n";
82
	echo 'graph_info some wordpress statistics of '.$d["name"]."\n";
83
	echo 'graph_category '.$category."\n";
84
	echo 'users.label Users'."\n";
85
	echo 'posts.label Posts'."\n";
86
	echo 'posts.draw LINE3'."\n";
87
	echo 'comments.label Comments'."\n";
88
	echo 'pingbacks.label Pingbacks'."\n";
89
    exit(0);
90

  
91
}else if($argv[1] == "autoconf") {
92
	if(file_exists($d["conf"])) {
93
		echo "yes";
94
		exit(0);
95
	 }else{
96
		echo "no (config does not exist)";
97
		exit(1);
98
	}
99
}
100

  
101
if(!empty($d["conf"])) {
102
	if(!file_exists($d["conf"])) {
103
		echo "Error: config does not exist!";
104
		exit(1);
105
	}
106
}
107

  
108
// INIT VARIABLES
109
$users     = 0;
110
$posts     = 0;
111
$comments  = 0;
112
$pingbacks = 0;
113

  
114
// GET DATA
115
mysql_connect($d["host"], $d["user"], $d["pass"]) or die("Error: Failed to connect to the MySQL database!");
116
mysql_select_db($d["dbnm"]) or die("Error: Failed to select database!");
117

  
118
$users     = mysql_result(mysql_query("SELECT COUNT(*) FROM ".$d["tbpf"]."users;"), 0);
119
$posts     = mysql_result(mysql_query("SELECT COUNT(*) FROM ".$d["tbpf"]."posts    WHERE post_status='publish' AND post_password='' AND post_type='post';"), 0);
120
$comments  = mysql_result(mysql_query("SELECT COUNT(*) FROM ".$d["tbpf"]."comments WHERE comment_approved='1' AND comment_type='';"), 0);
121
$pingbacks = mysql_result(mysql_query("SELECT COUNT(*) FROM ".$d["tbpf"]."comments WHERE comment_approved='1' AND comment_type='pingback';"), 0);
122

  
123
// OUTPUT DATA
124
echo     "users.value ".$users    ."\n";
125
echo     "posts.value ".$posts    ."\n";
126
echo  "comments.value ".$comments ."\n";
127
echo "pingbacks.value ".$pingbacks."\n";
128

  
129
?>

Formats disponibles : Unified diff