From 711726ab8fe7ef788a00e423d554f9cc1cd5002a Mon Sep 17 00:00:00 2001 From: ak4t0sh Date: Fri, 12 Sep 2014 18:29:18 +0200 Subject: [PATCH 01/12] initial commit --- plugins/moodle/moodle_users_online.php | 31 +++++++++++ plugins/moodle/moodle_users_total.php | 77 ++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 plugins/moodle/moodle_users_online.php create mode 100644 plugins/moodle/moodle_users_total.php diff --git a/plugins/moodle/moodle_users_online.php b/plugins/moodle/moodle_users_online.php new file mode 100644 index 00000000..ec9c8291 --- /dev/null +++ b/plugins/moodle/moodle_users_online.php @@ -0,0 +1,31 @@ +#!/usr/bin/php + + * @version 1.0 2014 + * + */ +$db = getenv('db'); +$type = getenv('type'); +$host = getenv('host'); +$user = getenv('user'); +$pass = getenv('pass'); +$port = getenv('port'); +if (!$port) + $port = 3306; \ No newline at end of file diff --git a/plugins/moodle/moodle_users_total.php b/plugins/moodle/moodle_users_total.php new file mode 100644 index 00000000..de529334 --- /dev/null +++ b/plugins/moodle/moodle_users_total.php @@ -0,0 +1,77 @@ +#!/usr/bin/php + + * @version 1.0 2014 + * + */ + +$dbh = null; +$db = getenv('db'); +$type = getenv('type'); +$host = getenv('host'); +$user = getenv('user'); +$pass = getenv('pass'); +$table_prefix = getenv('table_prefix'); +$port = getenv('port'); +if (!$port) + $port = 3306; +$graph_period = getenv('graph_period'); + + +if (count($argv) === 2 && $argv[1] === 'config') { + echo "graph_title Moodle Total Users\n"; + echo "graph_args --base 1000 --lower-limit 0\n"; + echo "graph_vlabel Total Users Count / ${graph_period}\n"; + echo "graph_category Moodle\n"; + echo "graph_scale no\n"; + echo "graph_info Displays the sum of users, as well as active count, in your Moodle site\n"; + + echo "users_total.label total users\n"; + echo "users_active.label active users\n"; + + echo "users_total.min 0\n"; + echo "users_active.min 0\n"; + + exit(0); +} + +try { + $dsn = $type . ':host=' . $host . ';port=' . $port . ';dbname=' . $db; + $dbh = new PDO($dsn, $user, $pass); +} catch (Exception $e) { + echo "Connection failed\n"; + exit(1); +} + + + +//All users +$nbusers = 0; +if (($stmt = $dbh->query("SELECT COUNT(id) FROM {$table_prefix}user")) != false) { + $nbusers = $stmt->fetchColumn(); +} +echo "users_total.value $nbusers\n"; + +//Active users (not deleted or suspended) +$nbusers = 0; +if (($stmt = $dbh->query("SELECT COUNT(id) FROM {$table_prefix}user WHERE deleted=0 AND suspended=0")) != false) { + $nbusers = $stmt->fetchColumn(); + echo "users_active.value $nbusers\n"; +} \ No newline at end of file From f3d7d0195c7ffc2ac22441a2986d7b05f754bb0e Mon Sep 17 00:00:00 2001 From: ak4t0sh Date: Mon, 15 Sep 2014 10:23:51 +0200 Subject: [PATCH 02/12] add suspended and deleted accounts --- plugins/moodle/moodle_users_total.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/plugins/moodle/moodle_users_total.php b/plugins/moodle/moodle_users_total.php index de529334..6182454d 100644 --- a/plugins/moodle/moodle_users_total.php +++ b/plugins/moodle/moodle_users_total.php @@ -41,13 +41,17 @@ if (count($argv) === 2 && $argv[1] === 'config') { echo "graph_vlabel Total Users Count / ${graph_period}\n"; echo "graph_category Moodle\n"; echo "graph_scale no\n"; - echo "graph_info Displays the sum of users, as well as active count, in your Moodle site\n"; + echo "graph_info Displays the sum of users, as well as active, suspended and deleted accounts, in your Moodle site\n"; echo "users_total.label total users\n"; echo "users_active.label active users\n"; + echo "users_suspended.label suspended users\n"; + echo "users_deleted.label deleted users\n"; echo "users_total.min 0\n"; echo "users_active.min 0\n"; + echo "users_suspended.min 0\n"; + echo "users_deleted.min 0\n"; exit(0); } @@ -74,4 +78,18 @@ $nbusers = 0; if (($stmt = $dbh->query("SELECT COUNT(id) FROM {$table_prefix}user WHERE deleted=0 AND suspended=0")) != false) { $nbusers = $stmt->fetchColumn(); echo "users_active.value $nbusers\n"; +} + +//Active users (not deleted or suspended) +$nbusers = 0; +if (($stmt = $dbh->query("SELECT COUNT(id) FROM {$table_prefix}user WHERE suspended=1 and deleted=0")) != false) { + $nbusers = $stmt->fetchColumn(); + echo "users_suspended.value $nbusers\n"; +} + +//Active users (not deleted or suspended) +$nbusers = 0; +if (($stmt = $dbh->query("SELECT COUNT(id) FROM {$table_prefix}user WHERE deleted=1")) != false) { + $nbusers = $stmt->fetchColumn(); + echo "users_deleted.value $nbusers\n"; } \ No newline at end of file From ef4bcb874d5505ff73195d6f011e64ee6ba0d75b Mon Sep 17 00:00:00 2001 From: ak4t0sh Date: Mon, 15 Sep 2014 15:56:48 +0200 Subject: [PATCH 03/12] set graph_period to 5 minutes + text changes in graph config --- plugins/moodle/moodle_users_total.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/moodle/moodle_users_total.php b/plugins/moodle/moodle_users_total.php index 6182454d..7ac7585e 100644 --- a/plugins/moodle/moodle_users_total.php +++ b/plugins/moodle/moodle_users_total.php @@ -32,13 +32,14 @@ $table_prefix = getenv('table_prefix'); $port = getenv('port'); if (!$port) $port = 3306; -$graph_period = getenv('graph_period'); +//$graph_period = getenv('graph_period'); +$graph_period = time() - 5*60; if (count($argv) === 2 && $argv[1] === 'config') { echo "graph_title Moodle Total Users\n"; echo "graph_args --base 1000 --lower-limit 0\n"; - echo "graph_vlabel Total Users Count / ${graph_period}\n"; + echo "graph_vlabel users\n"; echo "graph_category Moodle\n"; echo "graph_scale no\n"; echo "graph_info Displays the sum of users, as well as active, suspended and deleted accounts, in your Moodle site\n"; From 31412baabde8a973b5d1048d363677644dfe2263 Mon Sep 17 00:00:00 2001 From: ak4t0sh Date: Mon, 15 Sep 2014 16:02:43 +0200 Subject: [PATCH 04/12] implement online_users graph --- plugins/moodle/moodle_users_online.php | 34 +++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/plugins/moodle/moodle_users_online.php b/plugins/moodle/moodle_users_online.php index ec9c8291..959b359a 100644 --- a/plugins/moodle/moodle_users_online.php +++ b/plugins/moodle/moodle_users_online.php @@ -21,11 +21,43 @@ * @version 1.0 2014 * */ +$dbh = null; $db = getenv('db'); $type = getenv('type'); $host = getenv('host'); $user = getenv('user'); $pass = getenv('pass'); +$table_prefix = getenv('table_prefix'); $port = getenv('port'); if (!$port) - $port = 3306; \ No newline at end of file + $port = 3306; +//$graph_period = getenv('graph_period'); +$graph_period = time() - 5*60; + + +if (count($argv) === 2 && $argv[1] === 'config') { + echo "graph_title Moodle Online Users\n"; + echo "graph_args --base 1000 --lower-limit 0\n"; + echo "graph_vlabel users\n"; + echo "graph_category Moodle\n"; + echo "graph_scale no\n"; + echo "graph_info Displays the sum of online users in your Moodle site\n"; + echo "users_online.label online users\n"; + echo "users_online.min 0\n"; + exit(0); +} + +try { + $dsn = $type . ':host=' . $host . ';port=' . $port . ';dbname=' . $db; + $dbh = new PDO($dsn, $user, $pass); +} catch (Exception $e) { + echo "Connection failed\n"; + exit(1); +} + +//Online users +$nbusers = 0; +if (($stmt = $dbh->query("SELECT count(id) AS users FROM {$table_prefix}user WHERE lastaccess > $graph_period")) != false) { + $nbusers = $stmt->fetchColumn(); +} +echo "users_online.value $nbusers\n"; \ No newline at end of file From 43c46465920eae87cfb670163e335b6fe14fc683 Mon Sep 17 00:00:00 2001 From: ak4t0sh Date: Mon, 15 Sep 2014 18:42:57 +0200 Subject: [PATCH 05/12] add draw area --- plugins/moodle/moodle_users_online.php | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/moodle/moodle_users_online.php b/plugins/moodle/moodle_users_online.php index 959b359a..f06ad5b4 100644 --- a/plugins/moodle/moodle_users_online.php +++ b/plugins/moodle/moodle_users_online.php @@ -44,6 +44,7 @@ if (count($argv) === 2 && $argv[1] === 'config') { echo "graph_info Displays the sum of online users in your Moodle site\n"; echo "users_online.label online users\n"; echo "users_online.min 0\n"; + echo "users_online.draw AREA\n"; exit(0); } From 5ac6279f4461aec81a4307414d15d099b4d8c504 Mon Sep 17 00:00:00 2001 From: ak4t0sh Date: Mon, 15 Sep 2014 22:46:08 +0200 Subject: [PATCH 06/12] add module plugin --- plugins/moodle/moodle_modules_total.php | 75 +++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 plugins/moodle/moodle_modules_total.php diff --git a/plugins/moodle/moodle_modules_total.php b/plugins/moodle/moodle_modules_total.php new file mode 100644 index 00000000..33cedd4a --- /dev/null +++ b/plugins/moodle/moodle_modules_total.php @@ -0,0 +1,75 @@ +#!/usr/bin/php + + * @version 1.0 2014 + * + */ + +$dbh = null; +$db = getenv('db'); +$type = getenv('type'); +$host = getenv('host'); +$user = getenv('user'); +$pass = getenv('pass'); +$table_prefix = getenv('table_prefix'); +$port = getenv('port'); +if (!$port) + $port = 3306; +//$graph_period = getenv('graph_period'); +$graph_period = time() - 5*60; + + +try { + $dsn = $type . ':host=' . $host . ';port=' . $port . ';dbname=' . $db; + $dbh = new PDO($dsn, $user, $pass); +} catch (Exception $e) { + echo "Connection failed\n"; + exit(1); +} +//All users +$data = array(); +if (($stmt = $dbh->query("SELECT m.name as modulename, count(cm.id) as moduleinstance FROM {$table_prefix}modules m, {$table_prefix}course_modules cm WHERE cm.module=m.id GROUP BY cm.module ORDER BY m.name ASC")) != false) { + $data = $stmt->fetchAll(PDO::FETCH_OBJ); +} + +if (count($argv) === 2 && $argv[1] === 'config') { + echo "graph_title Moodle Modules\n"; + echo "graph_args --base 1000 --lower-limit 0\n"; + echo "graph_vlabel modules\n"; + echo "graph_category Moodle\n"; + echo "graph_scale no\n"; + echo "graph_info Displays the sum of module, as well as module instance number by type, in your Moodle site\n"; + + foreach($data as $entry) { + echo "modules_".$entry->modulename.".label ".$entry->modulename."\n"; + echo "modules_".$entry->modulename.".min 0\n"; + echo "modules_".$entry->modulename.".draw AREA\n"; + } + echo "modules_total.label total users\n"; + echo "modules_total.min 0\n"; + exit(0); +} +$total = 0; +foreach($data as $entry) { + echo "modules_".$entry->modulename.".label ".$entry->modulename."\n"; + echo "modules_".$entry->modulename.".value ".$entry->moduleinstance."\n"; + $total += $entry->moduleinstance; +} +echo "modules_total.value $total\n"; \ No newline at end of file From ac1f67b28e84be2349c25d16b9f72950896a754d Mon Sep 17 00:00:00 2001 From: ak4t0sh Date: Mon, 15 Sep 2014 23:10:00 +0200 Subject: [PATCH 07/12] remove computed total to let munin do the work --- plugins/moodle/moodle_modules_total.php | 8 ++------ plugins/moodle/moodle_users_total.php | 20 ++++---------------- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/plugins/moodle/moodle_modules_total.php b/plugins/moodle/moodle_modules_total.php index 33cedd4a..e9583b7e 100644 --- a/plugins/moodle/moodle_modules_total.php +++ b/plugins/moodle/moodle_modules_total.php @@ -56,20 +56,16 @@ if (count($argv) === 2 && $argv[1] === 'config') { echo "graph_category Moodle\n"; echo "graph_scale no\n"; echo "graph_info Displays the sum of module, as well as module instance number by type, in your Moodle site\n"; + echo "graph_total.label total\n"; foreach($data as $entry) { echo "modules_".$entry->modulename.".label ".$entry->modulename."\n"; echo "modules_".$entry->modulename.".min 0\n"; echo "modules_".$entry->modulename.".draw AREA\n"; } - echo "modules_total.label total users\n"; - echo "modules_total.min 0\n"; exit(0); } -$total = 0; foreach($data as $entry) { echo "modules_".$entry->modulename.".label ".$entry->modulename."\n"; echo "modules_".$entry->modulename.".value ".$entry->moduleinstance."\n"; - $total += $entry->moduleinstance; -} -echo "modules_total.value $total\n"; \ No newline at end of file +} \ No newline at end of file diff --git a/plugins/moodle/moodle_users_total.php b/plugins/moodle/moodle_users_total.php index 7ac7585e..890cb4f5 100644 --- a/plugins/moodle/moodle_users_total.php +++ b/plugins/moodle/moodle_users_total.php @@ -43,17 +43,14 @@ if (count($argv) === 2 && $argv[1] === 'config') { echo "graph_category Moodle\n"; echo "graph_scale no\n"; echo "graph_info Displays the sum of users, as well as active, suspended and deleted accounts, in your Moodle site\n"; + echo "graph_total total\n"; - echo "users_total.label total users\n"; - echo "users_active.label active users\n"; - echo "users_suspended.label suspended users\n"; - echo "users_deleted.label deleted users\n"; - - echo "users_total.min 0\n"; + echo "users_active.label active\n"; + echo "users_suspended.label suspended\n"; + echo "users_deleted.label deleted\n"; echo "users_active.min 0\n"; echo "users_suspended.min 0\n"; echo "users_deleted.min 0\n"; - exit(0); } @@ -65,15 +62,6 @@ try { exit(1); } - - -//All users -$nbusers = 0; -if (($stmt = $dbh->query("SELECT COUNT(id) FROM {$table_prefix}user")) != false) { - $nbusers = $stmt->fetchColumn(); -} -echo "users_total.value $nbusers\n"; - //Active users (not deleted or suspended) $nbusers = 0; if (($stmt = $dbh->query("SELECT COUNT(id) FROM {$table_prefix}user WHERE deleted=0 AND suspended=0")) != false) { From 24e415fec0ff0bd89416e50f300d6db79fe10d41 Mon Sep 17 00:00:00 2001 From: ak4t0sh Date: Mon, 15 Sep 2014 23:17:03 +0200 Subject: [PATCH 08/12] change graph draw to area mode --- plugins/moodle/moodle_users_total.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/moodle/moodle_users_total.php b/plugins/moodle/moodle_users_total.php index 890cb4f5..7387568a 100644 --- a/plugins/moodle/moodle_users_total.php +++ b/plugins/moodle/moodle_users_total.php @@ -49,8 +49,11 @@ if (count($argv) === 2 && $argv[1] === 'config') { echo "users_suspended.label suspended\n"; echo "users_deleted.label deleted\n"; echo "users_active.min 0\n"; + echo "users_active.draw AREA\n"; echo "users_suspended.min 0\n"; + echo "users_suspended.draw AREA\n"; echo "users_deleted.min 0\n"; + echo "users_deleted.draw AREA\n"; exit(0); } From afc0bcab08b88f4533169b6730d33f86b754bc99 Mon Sep 17 00:00:00 2001 From: ak4t0sh Date: Mon, 15 Sep 2014 23:26:34 +0200 Subject: [PATCH 09/12] remove useless variable --- plugins/moodle/moodle_modules_total.php | 2 -- plugins/moodle/moodle_users_total.php | 3 --- 2 files changed, 5 deletions(-) diff --git a/plugins/moodle/moodle_modules_total.php b/plugins/moodle/moodle_modules_total.php index e9583b7e..507d3222 100644 --- a/plugins/moodle/moodle_modules_total.php +++ b/plugins/moodle/moodle_modules_total.php @@ -32,8 +32,6 @@ $table_prefix = getenv('table_prefix'); $port = getenv('port'); if (!$port) $port = 3306; -//$graph_period = getenv('graph_period'); -$graph_period = time() - 5*60; try { diff --git a/plugins/moodle/moodle_users_total.php b/plugins/moodle/moodle_users_total.php index 7387568a..3d5d1cc8 100644 --- a/plugins/moodle/moodle_users_total.php +++ b/plugins/moodle/moodle_users_total.php @@ -32,9 +32,6 @@ $table_prefix = getenv('table_prefix'); $port = getenv('port'); if (!$port) $port = 3306; -//$graph_period = getenv('graph_period'); -$graph_period = time() - 5*60; - if (count($argv) === 2 && $argv[1] === 'config') { echo "graph_title Moodle Total Users\n"; From e0ed24496259ac723f9890fc2e6b2f90296f22a6 Mon Sep 17 00:00:00 2001 From: ak4t0sh Date: Tue, 16 Sep 2014 13:34:46 +0200 Subject: [PATCH 10/12] replace some draw area by draw stack --- plugins/moodle/moodle_modules_total.php | 5 +++-- plugins/moodle/moodle_users_total.php | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/moodle/moodle_modules_total.php b/plugins/moodle/moodle_modules_total.php index 507d3222..1407097b 100644 --- a/plugins/moodle/moodle_modules_total.php +++ b/plugins/moodle/moodle_modules_total.php @@ -55,11 +55,12 @@ if (count($argv) === 2 && $argv[1] === 'config') { echo "graph_scale no\n"; echo "graph_info Displays the sum of module, as well as module instance number by type, in your Moodle site\n"; echo "graph_total.label total\n"; - + $draw = "AREA"; foreach($data as $entry) { echo "modules_".$entry->modulename.".label ".$entry->modulename."\n"; echo "modules_".$entry->modulename.".min 0\n"; - echo "modules_".$entry->modulename.".draw AREA\n"; + echo "modules_".$entry->modulename.".draw $draw\n"; + $draw = "STACK"; } exit(0); } diff --git a/plugins/moodle/moodle_users_total.php b/plugins/moodle/moodle_users_total.php index 3d5d1cc8..eda1d12b 100644 --- a/plugins/moodle/moodle_users_total.php +++ b/plugins/moodle/moodle_users_total.php @@ -48,9 +48,9 @@ if (count($argv) === 2 && $argv[1] === 'config') { echo "users_active.min 0\n"; echo "users_active.draw AREA\n"; echo "users_suspended.min 0\n"; - echo "users_suspended.draw AREA\n"; + echo "users_suspended.draw STACK\n"; echo "users_deleted.min 0\n"; - echo "users_deleted.draw AREA\n"; + echo "users_deleted.draw STACK\n"; exit(0); } From 10ffec61bf9970d40bd41067192516ae37fe7d1b Mon Sep 17 00:00:00 2001 From: ak4t0sh Date: Tue, 16 Sep 2014 13:53:26 +0200 Subject: [PATCH 11/12] remove useless naming in query --- plugins/moodle/moodle_users_online.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/moodle/moodle_users_online.php b/plugins/moodle/moodle_users_online.php index f06ad5b4..22316762 100644 --- a/plugins/moodle/moodle_users_online.php +++ b/plugins/moodle/moodle_users_online.php @@ -58,7 +58,7 @@ try { //Online users $nbusers = 0; -if (($stmt = $dbh->query("SELECT count(id) AS users FROM {$table_prefix}user WHERE lastaccess > $graph_period")) != false) { +if (($stmt = $dbh->query("SELECT count(id) FROM {$table_prefix}user WHERE lastaccess > $graph_period")) != false) { $nbusers = $stmt->fetchColumn(); } echo "users_online.value $nbusers\n"; \ No newline at end of file From dd685310ab0362b6170a0aaab6ddd465776a6651 Mon Sep 17 00:00:00 2001 From: ak4t0sh Date: Tue, 16 Sep 2014 14:02:00 +0200 Subject: [PATCH 12/12] initial commit --- plugins/moodle/modules/moodle_mod_forum.php | 72 +++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 plugins/moodle/modules/moodle_mod_forum.php diff --git a/plugins/moodle/modules/moodle_mod_forum.php b/plugins/moodle/modules/moodle_mod_forum.php new file mode 100644 index 00000000..bbca5516 --- /dev/null +++ b/plugins/moodle/modules/moodle_mod_forum.php @@ -0,0 +1,72 @@ +#!/usr/bin/php + + * @version 1.0 2014 + * + */ +$dbh = null; +$db = getenv('db'); +$type = getenv('type'); +$host = getenv('host'); +$user = getenv('user'); +$pass = getenv('pass'); +$table_prefix = getenv('table_prefix'); +$port = getenv('port'); +if (!$port) + $port = 3306; +//$graph_period = getenv('graph_period'); +$graph_period = time() - 5*60; + + +if (count($argv) === 2 && $argv[1] === 'config') { + echo "graph_title Moodle Forum Posts\n"; + echo "graph_args --base 1000 --lower-limit 0\n"; + echo "graph_vlabel number\n"; + echo "graph_category Moodle\n"; + echo "graph_scale no\n"; + echo "graph_info Displays the sum of new forums posts / discussions in your Moodle site\n"; + echo "forum_posts.label posts\n"; + echo "forum_posts.min 0\n"; + echo "forum_posts.draw AREA\n"; + echo "forum_discussion.draw STACK\n"; + echo "forum_discussion.min 0\n"; + echo "forum_discussion.label discussions\n"; + exit(0); +} + +try { + $dsn = $type . ':host=' . $host . ';port=' . $port . ';dbname=' . $db; + $dbh = new PDO($dsn, $user, $pass); +} catch (Exception $e) { + echo "Connection failed\n"; + exit(1); +} + +$nb = 0; +if (($stmt = $dbh->query("SELECT count(id) FROM {$table_prefix}forum_posts WHERE timemodified > $graph_period")) != false) { + $nb = $stmt->fetchColumn(); +} +echo "forum_posts.value $nb\n"; + +$nb = 0; +if (($stmt = $dbh->query("SELECT count(id) FROM {$table_prefix}forum_discussions WHERE timemodified > $graph_period")) != false) { + $nb = $stmt->fetchColumn(); +} +echo "forum_discussions.value $nb\n"; \ No newline at end of file