Actions

 Language:
 RSS flow:


DESMOULINS Jérôme's Blog


  Rajouter des graphes à Nagios

 Jérôme
 Linux
 Informatique
 

Ayant besoin de suivre l'évolution de la mémoire d'une de mes machines, j'ai rajouter récemment à mon Nagios des graphes de suivi des données recueillies par les scripts de "check".

 

Pour cela, je me suis basé sur la solution Nagiosgraph. Elle n'a pas été trop difficile à mettre en oeuvre, et bien que non mise à jour depuis 2014, elle répond amplement à mon besoin.

 

Je peux désormais facilement suivre l'évolution la mémoire, les occupations disques, les derniers backups, etc... Voici une petite capture d'écran des graphes, une fois installés sur le serveur Nagios:

Installation

Pour installer NagiosGraph, il faut créer un répertoire sur son serveur, et télécharger les sources de l'application:

mkdir -p /opt/product/nagiosgraph

cd /opt/product/nagiosgraph

wget https://sourceforge.net/projects/nagiosgraph/files/nagiosgraph/1.5.2/nagiosgraph-1.5.2.tar.gz

tar xvf nagiosgraph-1.5.2.tar.gz

Une fois l'application téléchargée et décompressée, on vérifie que tous les composants requis sur le serveur sont bien présents. Ceci ce fait en lançant le script:

./install.pl --check-prereq

Si tout est correct, nous pouvons lancer l'installation:

./install.pl

Pour ma part, le script n'est pas arrivé à faire fonctionner correctement apache.

hecking required PERL modules
  Carp...1.42
  CGI...4.38
  Data::Dumper...2.167
  Digest::MD5...2.55
  File::Basename...2.85
  File::Find...1.34
  MIME::Base64...3.15
  POSIX...1.76
  RRDs...1.5001
  Time::HiRes...1.9741
checking optional PERL modules
  GD...2.66
  Nagios::Config...36
checking nagios installation
  found nagios exectuable at /usr/sbin/nagios3
  found nagios init script at /etc/init.d/nagios3
checking web server installation
  found apache executable at /usr/sbin/apache2
  found apache init script at /etc/init.d/apache2
Destination directory (prefix)? [/usr/local/nagiosgraph] /opt/products/nagiosgraph
Location of configuration files (etc-dir)? [/opt/products/nagiosgraph/etc]
Location of executables? [/opt/products/nagiosgraph/bin]
Location of CGI scripts? [/opt/products/nagiosgraph/cgi]
Location of documentation (doc-dir)? [/opt/products/nagiosgraph/doc]
Location of examples? [/opt/products/nagiosgraph/examples]
Location of CSS and JavaScript files? [/opt/products/nagiosgraph/share]
Location of utilities? [/opt/products/nagiosgraph/util]
Location of state files (var-dir)? [/opt/products/nagiosgraph/var]
Location of RRD files? [/opt/products/nagiosgraph/var/rrd]
Location of log files (log-dir)? [/opt/products/nagiosgraph/var/log]
Path of log file? [/opt/products/nagiosgraph/var/log/nagiosgraph.log]
Path of CGI log file? [/opt/products/nagiosgraph/var/log/nagiosgraph-cgi.log]
Base URL? [/nagiosgraph]
URL of CGI scripts? [/nagiosgraph/cgi-bin]
URL of CSS file? [/nagiosgraph/nagiosgraph.css]
URL of JavaScript file? [/nagiosgraph/nagiosgraph.js]
URL of Nagios CGI scripts? [/nagios/cgi-bin]
Path of Nagios performance data file? [/tmp/perfdata.log]
username or userid of Nagios user? [nagios]
username or userid of web server user? [www-data]
Modify the Nagios configuration? [n] y
Path of Nagios configuration file? [/etc/nagios3/nagios.cfg]  
Path of Nagios commands file? [/etc/nagios3/commands.cfg]
Modify the Apache configuration? [n] y
Path of Apache configuration directory? /etc/apache2
configuration:
  ng_prefix            /opt/products/nagiosgraph
  ng_etc_dir           /opt/products/nagiosgraph/etc
  ng_bin_dir           /opt/products/nagiosgraph/bin
  ng_cgi_dir           /opt/products/nagiosgraph/cgi
  ng_doc_dir           /opt/products/nagiosgraph/doc
  ng_examples_dir      /opt/products/nagiosgraph/examples
  ng_www_dir           /opt/products/nagiosgraph/share
  ng_util_dir          /opt/products/nagiosgraph/util
  ng_var_dir           /opt/products/nagiosgraph/var
  ng_rrd_dir           /opt/products/nagiosgraph/var/rrd
  ng_log_dir           /opt/products/nagiosgraph/var/log
  ng_log_file          /opt/products/nagiosgraph/var/log/nagiosgraph.log
  ng_cgilog_file       /opt/products/nagiosgraph/var/log/nagiosgraph-cgi.log
  ng_url               /nagiosgraph
  ng_cgi_url           /nagiosgraph/cgi-bin
  ng_css_url           /nagiosgraph/nagiosgraph.css
  ng_js_url            /nagiosgraph/nagiosgraph.js
  nagios_cgi_url       /nagios/cgi-bin
  nagios_perfdata_file /tmp/perfdata.log
  nagios_user          nagios
  www_user             www-data
  modify_nagios_config y
  nagios_config_file   /etc/nagios3/nagios.cfg
  nagios_commands_file /etc/nagios3/commands.cfg
  modify_apache_config y
  apache_config_dir    /etc/apache2
  apache_config_file   
Continue with this configuration? [y] n
installation aborted
root@bananapi:/opt/products/nagios/nagiosgraph-1.5.2# ./install.pl
checking required PERL modules
  Carp...1.42
  CGI...4.38
  Data::Dumper...2.167
  Digest::MD5...2.55
  File::Basename...2.85
  File::Find...1.34
  MIME::Base64...3.15
  POSIX...1.76
  RRDs...1.5001
  Time::HiRes...1.9741
checking optional PERL modules
  GD...2.66
  Nagios::Config...36
checking nagios installation
  found nagios exectuable at /usr/sbin/nagios3
  found nagios init script at /etc/init.d/nagios3
checking web server installation
  found apache executable at /usr/sbin/apache2
  found apache init script at /etc/init.d/apache2
Destination directory (prefix)? [/usr/local/nagiosgraph] /opt/products/nagiosgraph
Location of configuration files (etc-dir)? [/opt/products/nagiosgraph/etc]
Location of executables? [/opt/products/nagiosgraph/bin]
Location of CGI scripts? [/opt/products/nagiosgraph/cgi]
Location of documentation (doc-dir)? [/opt/products/nagiosgraph/doc]
Location of examples? [/opt/products/nagiosgraph/examples]
Location of CSS and JavaScript files? [/opt/products/nagiosgraph/share]
Location of utilities? [/opt/products/nagiosgraph/util]
Location of state files (var-dir)? [/opt/products/nagiosgraph/var]
Location of RRD files? [/opt/products/nagiosgraph/var/rrd]
Location of log files (log-dir)? [/opt/products/nagiosgraph/var/log]
Path of log file? [/opt/products/nagiosgraph/var/log/nagiosgraph.log]
Path of CGI log file? [/opt/products/nagiosgraph/var/log/nagiosgraph-cgi.log]
Base URL? [/nagiosgraph]
URL of CGI scripts? [/nagiosgraph/cgi-bin]
URL of CSS file? [/nagiosgraph/nagiosgraph.css]
URL of JavaScript file? [/nagiosgraph/nagiosgraph.js]
URL of Nagios CGI scripts? [/nagios/cgi-bin]
Path of Nagios performance data file? [/tmp/perfdata.log]
username or userid of Nagios user? [nagios]
username or userid of web server user? [www-data]
Modify the Nagios configuration? [n] y
Path of Nagios configuration file? [/etc/nagios3/nagios.cfg]
Path of Nagios commands file? [/etc/nagios3/commands.cfg]
Modify the Apache configuration? [n] y
Path of Apache configuration directory? /etc/apache2/apache2.conf
configuration:
  ng_prefix            /opt/products/nagiosgraph
  ng_etc_dir           /opt/products/nagiosgraph/etc
  ng_bin_dir           /opt/products/nagiosgraph/bin
  ng_cgi_dir           /opt/products/nagiosgraph/cgi
  ng_doc_dir           /opt/products/nagiosgraph/doc
  ng_examples_dir      /opt/products/nagiosgraph/examples
  ng_www_dir           /opt/products/nagiosgraph/share
  ng_util_dir          /opt/products/nagiosgraph/util
  ng_var_dir           /opt/products/nagiosgraph/var
  ng_rrd_dir           /opt/products/nagiosgraph/var/rrd
  ng_log_dir           /opt/products/nagiosgraph/var/log
  ng_log_file          /opt/products/nagiosgraph/var/log/nagiosgraph.log
  ng_cgilog_file       /opt/products/nagiosgraph/var/log/nagiosgraph-cgi.log
  ng_url               /nagiosgraph
  ng_cgi_url           /nagiosgraph/cgi-bin
  ng_css_url           /nagiosgraph/nagiosgraph.css
  ng_js_url            /nagiosgraph/nagiosgraph.js
  nagios_cgi_url       /nagios/cgi-bin
  nagios_perfdata_file /tmp/perfdata.log
  nagios_user          nagios
  www_user             www-data
  modify_nagios_config y
  nagios_config_file   /etc/nagios3/nagios.cfg
  nagios_commands_file /etc/nagios3/commands.cfg
  modify_apache_config y
  apache_config_dir    /etc/apache2/apache2.conf
  apache_config_file   
Continue with this configuration? [y] y
mkdir /opt/products/nagiosgraph
mkdir /opt/products/nagiosgraph/etc
move /opt/products/nagiosgraph/etc/nagiosgraph_de.conf to /opt/products/nagiosgraph/etc/nagiosgraph_de.conf.20181025203252
copy etc/nagiosgraph_de.conf to /opt/products/nagiosgraph/etc/nagiosgraph_de.conf
move /opt/products/nagiosgraph/etc/labels.conf to /opt/products/nagiosgraph/etc/labels.conf.20181025203252
copy etc/labels.conf to /opt/products/nagiosgraph/etc/labels.conf
move /opt/products/nagiosgraph/etc/hostdb.conf to /opt/products/nagiosgraph/etc/hostdb.conf.20181025203252
copy etc/hostdb.conf to /opt/products/nagiosgraph/etc/hostdb.conf
move /opt/products/nagiosgraph/etc/datasetdb.conf to /opt/products/nagiosgraph/etc/datasetdb.conf.20181025203252
copy etc/datasetdb.conf to /opt/products/nagiosgraph/etc/datasetdb.conf
move /opt/products/nagiosgraph/etc/access.conf to /opt/products/nagiosgraph/etc/access.conf.20181025203252
copy etc/access.conf to /opt/products/nagiosgraph/etc/access.conf
move /opt/products/nagiosgraph/etc/servdb.conf to /opt/products/nagiosgraph/etc/servdb.conf.20181025203252
copy etc/servdb.conf to /opt/products/nagiosgraph/etc/servdb.conf
move /opt/products/nagiosgraph/etc/groupdb.conf to /opt/products/nagiosgraph/etc/groupdb.conf.20181025203252
copy etc/groupdb.conf to /opt/products/nagiosgraph/etc/groupdb.conf
move /opt/products/nagiosgraph/etc/nagiosgraph_es.conf to /opt/products/nagiosgraph/etc/nagiosgraph_es.conf.20181025203252
copy etc/nagiosgraph_es.conf to /opt/products/nagiosgraph/etc/nagiosgraph_es.conf
move /opt/products/nagiosgraph/etc/nagiosgraph_fr.conf to /opt/products/nagiosgraph/etc/nagiosgraph_fr.conf.20181025203252
copy etc/nagiosgraph_fr.conf to /opt/products/nagiosgraph/etc/nagiosgraph_fr.conf
move /opt/products/nagiosgraph/etc/rrdopts.conf to /opt/products/nagiosgraph/etc/rrdopts.conf.20181025203252
copy etc/rrdopts.conf to /opt/products/nagiosgraph/etc/rrdopts.conf
move /opt/products/nagiosgraph/etc/nagiosgraph.conf to /opt/products/nagiosgraph/etc/nagiosgraph.conf.20181025203252
copy etc/nagiosgraph.conf to /opt/products/nagiosgraph/etc/nagiosgraph.conf
move /opt/products/nagiosgraph/etc/map to /opt/products/nagiosgraph/etc/map.20181025203252
copy etc/map to /opt/products/nagiosgraph/etc/map
copy etc/ngshared.pm to /opt/products/nagiosgraph/etc
replace text in /opt/products/nagiosgraph/etc/nagiosgraph.conf
move /opt/products/nagiosgraph/etc/nagiosgraph.conf-bak to /opt/products/nagiosgraph/etc/nagiosgraph.conf
replace text in /opt/products/nagiosgraph/etc/nagiosgraph.conf
move /opt/products/nagiosgraph/etc/nagiosgraph.conf-bak to /opt/products/nagiosgraph/etc/nagiosgraph.conf
write stub to /opt/products/nagiosgraph/etc/nagiosgraph-nagios.cfg
write stub to /opt/products/nagiosgraph/etc/nagiosgraph-commands.cfg
write stub to /opt/products/nagiosgraph/etc/nagiosgraph-apache.conf
mkdir /opt/products/nagiosgraph/cgi
copy cgi/showconfig.cgi to /opt/products/nagiosgraph/cgi
replace text in /opt/products/nagiosgraph/cgi/showconfig.cgi
move /opt/products/nagiosgraph/cgi/showconfig.cgi-bak to /opt/products/nagiosgraph/cgi/showconfig.cgi
chmod 755 on /opt/products/nagiosgraph/cgi/showconfig.cgi
copy cgi/showgroup.cgi to /opt/products/nagiosgraph/cgi
replace text in /opt/products/nagiosgraph/cgi/showgroup.cgi
move /opt/products/nagiosgraph/cgi/showgroup.cgi-bak to /opt/products/nagiosgraph/cgi/showgroup.cgi
chmod 755 on /opt/products/nagiosgraph/cgi/showgroup.cgi
copy cgi/show.cgi to /opt/products/nagiosgraph/cgi
replace text in /opt/products/nagiosgraph/cgi/show.cgi
move /opt/products/nagiosgraph/cgi/show.cgi-bak to /opt/products/nagiosgraph/cgi/show.cgi
chmod 755 on /opt/products/nagiosgraph/cgi/show.cgi
copy cgi/testcolor.cgi to /opt/products/nagiosgraph/cgi
replace text in /opt/products/nagiosgraph/cgi/testcolor.cgi
move /opt/products/nagiosgraph/cgi/testcolor.cgi-bak to /opt/products/nagiosgraph/cgi/testcolor.cgi
chmod 755 on /opt/products/nagiosgraph/cgi/testcolor.cgi
copy cgi/showgraph.cgi to /opt/products/nagiosgraph/cgi
replace text in /opt/products/nagiosgraph/cgi/showgraph.cgi
move /opt/products/nagiosgraph/cgi/showgraph.cgi-bak to /opt/products/nagiosgraph/cgi/showgraph.cgi
chmod 755 on /opt/products/nagiosgraph/cgi/showgraph.cgi
copy cgi/showservice.cgi to /opt/products/nagiosgraph/cgi
replace text in /opt/products/nagiosgraph/cgi/showservice.cgi
move /opt/products/nagiosgraph/cgi/showservice.cgi-bak to /opt/products/nagiosgraph/cgi/showservice.cgi
chmod 755 on /opt/products/nagiosgraph/cgi/showservice.cgi
copy cgi/export.cgi to /opt/products/nagiosgraph/cgi
replace text in /opt/products/nagiosgraph/cgi/export.cgi
move /opt/products/nagiosgraph/cgi/export.cgi-bak to /opt/products/nagiosgraph/cgi/export.cgi
chmod 755 on /opt/products/nagiosgraph/cgi/export.cgi
copy cgi/showhost.cgi to /opt/products/nagiosgraph/cgi
replace text in /opt/products/nagiosgraph/cgi/showhost.cgi
move /opt/products/nagiosgraph/cgi/showhost.cgi-bak to /opt/products/nagiosgraph/cgi/showhost.cgi
chmod 755 on /opt/products/nagiosgraph/cgi/showhost.cgi
mkdir /opt/products/nagiosgraph/bin
copy lib/insert.pl to /opt/products/nagiosgraph/bin
replace text in /opt/products/nagiosgraph/bin/insert.pl
move /opt/products/nagiosgraph/bin/insert.pl-bak to /opt/products/nagiosgraph/bin/insert.pl
chmod 755 on /opt/products/nagiosgraph/bin/insert.pl
mkdir /opt/products/nagiosgraph/share
move /opt/products/nagiosgraph/share/nagiosgraph.css to /opt/products/nagiosgraph/share/nagiosgraph.css.20181025203252
copy share/nagiosgraph.css to /opt/products/nagiosgraph/share/nagiosgraph.css
copy share/nagiosgraph.js to /opt/products/nagiosgraph/share
mkdir /opt/products/nagiosgraph/doc
copy AUTHORS to /opt/products/nagiosgraph/doc
copy CHANGELOG to /opt/products/nagiosgraph/doc
copy INSTALL to /opt/products/nagiosgraph/doc
copy README to /opt/products/nagiosgraph/doc
copy TODO to /opt/products/nagiosgraph/doc
mkdir /opt/products/nagiosgraph/examples
copy examples/map_examples to /opt/products/nagiosgraph/examples
copy examples/insert.sh to /opt/products/nagiosgraph/examples
copy examples/nagiosgraph-logrotate to /opt/products/nagiosgraph/examples
copy examples/nagiosgraph-apache.conf to /opt/products/nagiosgraph/examples
copy examples/map_1_4_3 to /opt/products/nagiosgraph/examples
copy examples/nagiosgraph-nagios.cfg to /opt/products/nagiosgraph/examples
copy examples/map_minimal to /opt/products/nagiosgraph/examples
copy examples/map_1_3 to /opt/products/nagiosgraph/examples
copy examples/graphed-service.cfg to /opt/products/nagiosgraph/examples
copy examples/nagiosgraph.1.css to /opt/products/nagiosgraph/examples
copy examples/map_mwall to /opt/products/nagiosgraph/examples
copy examples/map_1_4_4 to /opt/products/nagiosgraph/examples
copy examples/map_1_4_5 to /opt/products/nagiosgraph/examples
copy examples/graphed-host.cfg to /opt/products/nagiosgraph/examples
copy examples/nagiosgraph.2.css to /opt/products/nagiosgraph/examples
copy examples/nagiosgraph-commands.cfg to /opt/products/nagiosgraph/examples
copy share/graph.gif to /opt/products/nagiosgraph/examples
copy share/nagiosgraph.ssi to /opt/products/nagiosgraph/examples
mkdir /opt/products/nagiosgraph/util
copy utils/testentry.pl to /opt/products/nagiosgraph/util
copy utils/flat2hier.pl to /opt/products/nagiosgraph/util
chmod 755 on /opt/products/nagiosgraph/util/testentry.pl
chmod 755 on /opt/products/nagiosgraph/util/flat2hier.pl
mkdir /opt/products/nagiosgraph/var/rrd
chmod 755 on /opt/products/nagiosgraph/var/rrd
chown nagios,- on /opt/products/nagiosgraph/var/rrd
touching /opt/products/nagiosgraph/var/log/nagiosgraph.log
chmod 644 on /opt/products/nagiosgraph/var/log/nagiosgraph.log
chown nagios,- on /opt/products/nagiosgraph/var/log/nagiosgraph.log
touching /opt/products/nagiosgraph/var/log/nagiosgraph-cgi.log
chmod 644 on /opt/products/nagiosgraph/var/log/nagiosgraph-cgi.log
chown www-data,- on /opt/products/nagiosgraph/var/log/nagiosgraph-cgi.log
append to /etc/nagios3/nagios.cfg
copy /etc/nagios3/nagios.cfg to /etc/nagios3/nagios.cfg.tmp
move /etc/nagios3/nagios.cfg to /etc/nagios3/nagios.cfg-20181025.2032
move /etc/nagios3/nagios.cfg.tmp to /etc/nagios3/nagios.cfg
append to /etc/nagios3/commands.cfg
copy /etc/nagios3/commands.cfg to /etc/nagios3/commands.cfg.tmp
move /etc/nagios3/commands.cfg to /etc/nagios3/commands.cfg-20181025.2032
move /etc/nagios3/commands.cfg.tmp to /etc/nagios3/commands.cfg
move /opt/products/nagiosgraph/etc/nagiosgraph-apache.conf to /etc/apache2/apache2.conf/nagiosgraph.conf
*** cannot rename /opt/products/nagiosgraph/etc/nagiosgraph-apache.conf to /etc/apache2/apache2.conf/nagiosgraph.conf: Not a directory

  * Check the nagios configuration:

/usr/sbin/nagios3 -v /etc/nagios3/nagios.cfg

  * Restart nagios to start data collection:

/etc/init.d/nagios3 restart

  * Restart apache to enable display of graphs:

/etc/init.d/apache2 restart

  * To enable graph links and mouseovers, see README sections:
       Displaying Per-Service and Per-Host Graph Icons and Links
       Displaying Graphs in Nagios Mouseovers

*** one or more problems were detected!

Chez moi, l'installation s'est terminée sur cette erreur. Nagiosgraph n'est pas arrivé à modifier la configuration d'Apache. Je l'ai donc fait à la main.

Correction de l'erreur d'installation

J'ai simplement ajouté les lignes suivantes dans le fichier /etc/nagios3/apache2.conf:

### FOR NagiosGraph
# enable nagiosgraph CGI scripts
ScriptAlias /nagiosgraph/cgi-bin "/opt/products/nagiosgraph/cgi"

   Options ExecCGI
   AllowOverride All
   Require all granted
#   AuthName "Nagios Access"
#   AuthType Basic
#   AuthUserFile NAGIOS_ETC_DIR/htpasswd.users
#   Require valid-user

# enable nagiosgraph CSS and JavaScript
Alias /nagiosgraph "/opt/products/nagiosgraph/share"

   Options None
   AllowOverride All
  Require all granted

et relancé Apache.

Vérification de l'installation

Normallement, à la fin de l'installation, les fichiers suivants sont mis à jour:

/etc/nagios3/nagios.cfg

Les lignes suivantes ont été ajoutées:

# begin nagiosgraph configuration
# process nagios performance data using nagiosgraph
process_performance_data=1
service_perfdata_file=/tmp/perfdata.log
service_perfdata_file_template=$LASTSERVICECHECK$||$HOSTNAME$||$SERVICEDESC$||$SERVICEOUTPUT$||$SERVICEPERFDATA$
service_perfdata_file_mode=a
service_perfdata_file_processing_interval=30
service_perfdata_file_processing_command=process-service-perfdata-for-nagiosgraph
# end nagiosgraph configuration

/usr/local/nagios/etc/objects/commands.cfg

Les lignes suivantes ont été ajoutées:

# begin nagiosgraph configuration
# command to process nagios performance data for nagiosgraph
define command {
  command_name process-service-perfdata-for-nagiosgraph
  command_line /opt/products/nagiosgraph/bin/insert.pl
}
# end nagiosgraph configuration

La configuration de base a été effectuée.

Ajout des liens NagiosGraph à la configuration

Déclaration du service "graphed-service"

Editer le fichier /etc/nagios3/conf.d/services_nagios2.cfg et y ajouter les lignes suivantes:

# For NagiosGraph
 define service {
      name        graphed-service
      action_url    /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$' onMouseOver='showGraphPopup(this)' onMouseOut='hideGraphPopup()' rel='/nagiosgraph
/cgi-bin/showgraph.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&period=week&rrdopts=-w+450+-j
    }

Ajout du lien pour vos contrôles existants

Pour chaque graphe à ajouter à l'interface graphique de Nagios, il suffit de rajouter le service "graphed-service" à votre contrôle existant.

Exemple:

define service{
        use                             generic-service,graphed-service         ; Name of service template to use
        host_name                       localhost
        service_description             Disk Space: /
        check_command                   check_disk!30%!25%!/
        }

Relancez maintenant votre Nagios et votre serveur Apache, et vous devriez avoir les liens sur votre interface:

 

Conclusion

Obtenir un service de graphes intégré en moins de 30 min à l'interface graphique de Nagios et sans avoir à trop modifier la configuration, voilà pour la principale information à retenir. Je profite depuis d'un historique permettant de voir l'évolution de mes services supervisés, et cela est bien pratique.

Lien

Voici le lien vers le site de Nagiosgraph:

http://nagiosgraph.sourceforge.net/

 

 

 

 

Back