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 diff --git a/plugins/moodle/moodle_modules_total.php b/plugins/moodle/moodle_modules_total.php new file mode 100644 index 00000000..1407097b --- /dev/null +++ b/plugins/moodle/moodle_modules_total.php @@ -0,0 +1,70 @@ +#!/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; + + +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"; + 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 $draw\n"; + $draw = "STACK"; + } + exit(0); +} +foreach($data as $entry) { + echo "modules_".$entry->modulename.".label ".$entry->modulename."\n"; + echo "modules_".$entry->modulename.".value ".$entry->moduleinstance."\n"; +} \ No newline at end of file diff --git a/plugins/moodle/moodle_users_online.php b/plugins/moodle/moodle_users_online.php new file mode 100644 index 00000000..22316762 --- /dev/null +++ b/plugins/moodle/moodle_users_online.php @@ -0,0 +1,64 @@ +#!/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 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"; + echo "users_online.draw AREA\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) FROM {$table_prefix}user WHERE lastaccess > $graph_period")) != false) { + $nbusers = $stmt->fetchColumn(); +} +echo "users_online.value $nbusers\n"; \ 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..eda1d12b --- /dev/null +++ b/plugins/moodle/moodle_users_total.php @@ -0,0 +1,84 @@ +#!/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; + +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 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"; + echo "graph_total total\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_active.draw AREA\n"; + echo "users_suspended.min 0\n"; + echo "users_suspended.draw STACK\n"; + echo "users_deleted.min 0\n"; + echo "users_deleted.draw STACK\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); +} + +//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"; +} + +//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