root / plugins / moodle / modules / moodle_mod_quiz.php @ 85d1b93c
Historique | Voir | Annoter | Télécharger (1,63 ko)
| 1 | 85d1b93c | ak4t0sh | #!/usr/bin/php |
|---|---|---|---|
| 2 | <?php
|
||
| 3 | /**
|
||
| 4 | * Moodle module quiz
|
||
| 5 | * Munin plugin to count new quiz attempts
|
||
| 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 | $dbh = null; |
||
| 25 | $db = getenv('db'); |
||
| 26 | $type = getenv('type'); |
||
| 27 | $host = getenv('host'); |
||
| 28 | $user = getenv('user'); |
||
| 29 | $pass = getenv('pass'); |
||
| 30 | $table_prefix = getenv('table_prefix'); |
||
| 31 | $port = getenv('port'); |
||
| 32 | if (!$port) |
||
| 33 | $port = 3306; |
||
| 34 | //$graph_period = getenv('graph_period');
|
||
| 35 | $graph_period = time() - 5*60; |
||
| 36 | |||
| 37 | |||
| 38 | if (count($argv) === 2 && $argv[1] === 'config') { |
||
| 39 | echo "graph_title Moodle Quiz Attempts\n"; |
||
| 40 | echo "graph_args --base 1000 --lower-limit 0\n"; |
||
| 41 | echo "graph_vlabel attempts\n"; |
||
| 42 | echo "graph_category Moodle\n"; |
||
| 43 | echo "graph_scale no\n"; |
||
| 44 | echo "graph_info Displays the sum quiz attempts in your Moodle site\n"; |
||
| 45 | echo "quiz_attempts.label attempts\n"; |
||
| 46 | echo "quiz_attempts.min 0\n"; |
||
| 47 | echo "quiz_attempts.draw AREA\n"; |
||
| 48 | exit(0); |
||
| 49 | } |
||
| 50 | |||
| 51 | try {
|
||
| 52 | $dsn = $type . ':host=' . $host . ';port=' . $port . ';dbname=' . $db; |
||
| 53 | $dbh = new PDO($dsn, $user, $pass); |
||
| 54 | } catch (Exception $e) { |
||
| 55 | echo "Connection failed\n"; |
||
| 56 | exit(1); |
||
| 57 | } |
||
| 58 | |||
| 59 | $nb = 0; |
||
| 60 | if (($stmt = $dbh->query("SELECT count(id) FROM {$table_prefix}quiz_attempts where timemodified > $graph_period")) != false) { |
||
| 61 | $nb = $stmt->fetchColumn(); |
||
| 62 | } |
||
| 63 | echo "quiz_attempts.value $nb\n"; |
