<commit_before>#!/usr/bin/php5
<?php
$doc = <<<CUT
=head1 NAME

chamilo_registered_courses - Munin plugin to monitor the number of courses created on Chamilo portals.

=head1 APPLICABLE SYSTEMS

Chamilo 1.* web applications.

=head1 CONFIGURATION

The plugin needs access to the root web directory /var/www (or any other given
path) in order to scan for Chamilo installations. It also offers a way to 
define subdirs if your Chamilo portals are generally stored under two folder
levels inside /var/www/. The plugin also needs the possibility to execute PHP
on the command line (php-cli package) and to connect to a MySQL database
(php5-mysql package).

=head1 INTERPRETATION

The plugin shows the number of courses at any given time for any
Chamilo portal, indicating the URL of the corresponding portal.

=head1 MAGIC MARKERS

  #%# family=auto
  #%# capabilities=autoconf

=head1 BUGS

None known of

=head1 VERSION

  0.2

=head1 AUTHOR

<NAME> <<EMAIL>>

=head1 LICENSE

AGPLv3

=cut
CUT;

ini_set('error_reporting','E_ALL & ~E_WARNING & ~E_NOTICE');
$bd = '/var/www';
$sub = '/www';
$connections = get_courses($bd, $sub); 
$output = '';
if ( !empty($argv[1]) && $argv[1] == 'config') {
  // Global Munin attr., see http://munin-monitoring.org/wiki/protocol-config
  $output .= "graph_title Chamilo registered courses v2\n";
  //$output .= "graph_args --lower-limit 0\n";
  $output .= "graph_args --lower-limit 0 --base 1000 --logarithmic'\n";
  $output .= "graph_category chamilo\n";
  $output .= "graph_info This graph shows the number of courses created on Chamilo portals over time.\n";
  $output .= "graph_vlabel Registered courses\n";
  $output .= "graph_scale off\n";
  foreach ($connections as $portal => $num) {
    $warning = 1000;
    $critical = 2000;
    $output .= "portal$portal.label Host $portal\n";
//    $output .= "portal$portal.type DERIVE\n";
    //$output .= "portal$portal.max 500\n";
//    $output .= "portal$portal.min 0\n";
//    $output .= "portal$portal.max 11000\n";
    $output .= "portal$portal.warning $warning\n";
    $output .= "portal$portal.critical $critical\n";
    $output .= "portal$portal.draw LINE2\n";
  }
  file_put_contents('/tmp/get_registered_courses_config',$output);
  exit;
}
if (is_array($connections) && count($connections)>0) {
  foreach ($connections as $portal => $num) {
    $output .= "portal$portal.value $num\n";
  }
}
file_put_contents('/tmp/get_registered_courses',$output);<commit_msg>Update warning and critical limits for courses to 4K and 5K: for organizations that use theses scripts, it is likely that the 1000 and 2000 limits will very quickly be passed<commit_after>#!/usr/bin/php5
<?php
$doc = <<<CUT
=head1 NAME

chamilo_registered_courses - Munin plugin to monitor the number of courses created on Chamilo portals.

=head1 APPLICABLE SYSTEMS

Chamilo 1.* web applications.

=head1 CONFIGURATION

The plugin needs access to the root web directory /var/www (or any other given
path) in order to scan for Chamilo installations. It also offers a way to 
define subdirs if your Chamilo portals are generally stored under two folder
levels inside /var/www/. The plugin also needs the possibility to execute PHP
on the command line (php-cli package) and to connect to a MySQL database
(php5-mysql package).

=head1 INTERPRETATION

The plugin shows the number of courses at any given time for any
Chamilo portal, indicating the URL of the corresponding portal.

=head1 MAGIC MARKERS

  #%# family=auto
  #%# capabilities=autoconf

=head1 BUGS

None known of

=head1 VERSION

  0.2

=head1 AUTHOR

<NAME> <<EMAIL>>

=head1 LICENSE

AGPLv3

=cut
CUT;

ini_set('error_reporting','E_ALL & ~E_WARNING & ~E_NOTICE');
$bd = '/var/www';
$sub = '/www';
$connections = get_courses($bd, $sub); 
$output = '';
if ( !empty($argv[1]) && $argv[1] == 'config') {
  // Global Munin attr., see http://munin-monitoring.org/wiki/protocol-config
  $output .= "graph_title Chamilo registered courses v2\n";
  //$output .= "graph_args --lower-limit 0\n";
  $output .= "graph_args --lower-limit 0 --base 1000 --logarithmic'\n";
  $output .= "graph_category chamilo\n";
  $output .= "graph_info This graph shows the number of courses created on Chamilo portals over time.\n";
  $output .= "graph_vlabel Registered courses\n";
  $output .= "graph_scale off\n";
  foreach ($connections as $portal => $num) {
    $warning = 4000;
    $critical = 5000;
    $output .= "portal$portal.label Host $portal\n";
//    $output .= "portal$portal.type DERIVE\n";
    //$output .= "portal$portal.max 500\n";
//    $output .= "portal$portal.min 0\n";
//    $output .= "portal$portal.max 11000\n";
    $output .= "portal$portal.warning $warning\n";
    $output .= "portal$portal.critical $critical\n";
    $output .= "portal$portal.draw LINE2\n";
  }
  file_put_contents('/tmp/get_registered_courses_config',$output);
  exit;
}
if (is_array($connections) && count($connections)>0) {
  foreach ($connections as $portal => $num) {
    $output .= "portal$portal.value $num\n";
  }
}
file_put_contents('/tmp/get_registered_courses',$output);
{'fraction_non_alphanumeric': 0.1366238894373149, 'fraction_numerical': 0.01895360315893386, 'mean_word_length': 4.0009871668311945, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 8, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6793045', 'n_tokens_mistral': 1772, 'n_tokens_neox': 1703, 'n_words': 531}