root / plugins / moodle / moodle_users_total.php @ ac1f67b2
Historique | Voir | Annoter | Télécharger (2,34 ko)
| 1 | 711726ab | ak4t0sh | #!/usr/bin/php |
|---|---|---|---|
| 2 | <?php
|
||
| 3 | /**
|
||
| 4 | * Moodle Users Total
|
||
| 5 | * Munin plugin to count total users
|
||
| 6 | *
|
||
| 7 | * It's required to define a container entry for this plugin in your
|
||
| 8 | * /etc/munin/plugin-conf.d/munin-node (or a separate and dedicated file).
|
||
| 9 | *
|
||
| 10 | * @example Example entry for configuration:
|
||
| 11 | * [moodle*]
|
||
| 12 | * env.type mysql
|
||
| 13 | * env.db moodle
|
||
| 14 | * env.user mysql_user
|
||
| 15 | * env.pass mysql_pass
|
||
| 16 | * env.host localhost
|
||
| 17 | * env.port 3306
|
||
| 18 | * env.table_prefix mdl_
|
||
| 19 | *
|
||
| 20 | * @author Arnaud Trouvé <ak4t0sh@free.fr>
|
||
| 21 | * @version 1.0 2014
|
||
| 22 | *
|
||
| 23 | */
|
||
| 24 | |||
| 25 | $dbh = null; |
||
| 26 | $db = getenv('db'); |
||
| 27 | $type = getenv('type'); |
||
| 28 | $host = getenv('host'); |
||
| 29 | $user = getenv('user'); |
||
| 30 | $pass = getenv('pass'); |
||
| 31 | $table_prefix = getenv('table_prefix'); |
||
| 32 | $port = getenv('port'); |
||
| 33 | if (!$port) |
||
| 34 | $port = 3306; |
||
| 35 | ef4bcb87 | ak4t0sh | //$graph_period = getenv('graph_period');
|
| 36 | $graph_period = time() - 5*60; |
||
| 37 | 711726ab | ak4t0sh | |
| 38 | |||
| 39 | if (count($argv) === 2 && $argv[1] === 'config') { |
||
| 40 | echo "graph_title Moodle Total Users\n"; |
||
| 41 | echo "graph_args --base 1000 --lower-limit 0\n"; |
||
| 42 | ef4bcb87 | ak4t0sh | echo "graph_vlabel users\n"; |
| 43 | 711726ab | ak4t0sh | echo "graph_category Moodle\n"; |
| 44 | echo "graph_scale no\n"; |
||
| 45 | f3d7d019 | ak4t0sh | echo "graph_info Displays the sum of users, as well as active, suspended and deleted accounts, in your Moodle site\n"; |
| 46 | ac1f67b2 | ak4t0sh | echo "graph_total total\n"; |
| 47 | 711726ab | ak4t0sh | |
| 48 | ac1f67b2 | ak4t0sh | echo "users_active.label active\n"; |
| 49 | echo "users_suspended.label suspended\n"; |
||
| 50 | echo "users_deleted.label deleted\n"; |
||
| 51 | 711726ab | ak4t0sh | echo "users_active.min 0\n"; |
| 52 | f3d7d019 | ak4t0sh | echo "users_suspended.min 0\n"; |
| 53 | echo "users_deleted.min 0\n"; |
||
| 54 | 711726ab | ak4t0sh | exit(0); |
| 55 | } |
||
| 56 | |||
| 57 | try {
|
||
| 58 | $dsn = $type . ':host=' . $host . ';port=' . $port . ';dbname=' . $db; |
||
| 59 | $dbh = new PDO($dsn, $user, $pass); |
||
| 60 | } catch (Exception $e) { |
||
| 61 | echo "Connection failed\n"; |
||
| 62 | exit(1); |
||
| 63 | } |
||
| 64 | |||
| 65 | //Active users (not deleted or suspended)
|
||
| 66 | $nbusers = 0; |
||
| 67 | if (($stmt = $dbh->query("SELECT COUNT(id) FROM {$table_prefix}user WHERE deleted=0 AND suspended=0")) != false) { |
||
| 68 | $nbusers = $stmt->fetchColumn(); |
||
| 69 | echo "users_active.value $nbusers\n"; |
||
| 70 | f3d7d019 | ak4t0sh | } |
| 71 | |||
| 72 | //Active users (not deleted or suspended)
|
||
| 73 | $nbusers = 0; |
||
| 74 | if (($stmt = $dbh->query("SELECT COUNT(id) FROM {$table_prefix}user WHERE suspended=1 and deleted=0")) != false) { |
||
| 75 | $nbusers = $stmt->fetchColumn(); |
||
| 76 | echo "users_suspended.value $nbusers\n"; |
||
| 77 | } |
||
| 78 | |||
| 79 | //Active users (not deleted or suspended)
|
||
| 80 | $nbusers = 0; |
||
| 81 | if (($stmt = $dbh->query("SELECT COUNT(id) FROM {$table_prefix}user WHERE deleted=1")) != false) { |
||
| 82 | $nbusers = $stmt->fetchColumn(); |
||
| 83 | echo "users_deleted.value $nbusers\n"; |
||
| 84 | 711726ab | ak4t0sh | } |
