Herramientas de usuario

Herramientas del sitio


manuales:nagios:capacitacion:mk_livestatus

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

Próxima revisión
Revisión previa
manuales:nagios:capacitacion:mk_livestatus [2015/09/18 18:07] – creado cayumanuales:nagios:capacitacion:mk_livestatus [2016/03/21 18:49] (actual) – [Compilación] cayu
Línea 23: Línea 23:
 Esto es no sólo un enfoque increíblemente simple, si no también muy rápido. Algunas ventajas son: Esto es no sólo un enfoque increíblemente simple, si no también muy rápido. Algunas ventajas son:
  
-    * Otro entonces NDO, utilizando Livestatus no impone una carga mensurable de su CPU para nada. Sólo en el tratamiento de las consultas de una cantidad muy pequeña de la CPU es necesario. Pero eso ni siquiera se bloqueará Nagios. +    * Livestatus no impone una carga mensurable de su CPU para nada. Sólo en el tratamiento de las consultas de una cantidad muy pequeña de la CPU es necesario. Pero eso ni siquiera se bloqueará Nagios.
     * Livestatus produce cero / S de disco cuando quering datos de estado.     * Livestatus produce cero / S de disco cuando quering datos de estado.
     * Acceso a los datos es mucho más rápido que analizar status.dat o consultar una base de datos SQL.     * Acceso a los datos es mucho más rápido que analizar status.dat o consultar una base de datos SQL.
Línea 33: Línea 32:
 En el mismo tiempo, ofrece a sus Livestatus propio lenguaje de consulta que es simple de entender, ofrece la mayoría de la flexibilidad de SQL e incluso más en algunos casos. Es un protocolo rápido, ligero y no necesita un cliente binario. Incluso, pueden obtener acceso a los datos sin ningún tipo de software especial de ayuda.  En el mismo tiempo, ofrece a sus Livestatus propio lenguaje de consulta que es simple de entender, ofrece la mayoría de la flexibilidad de SQL e incluso más en algunos casos. Es un protocolo rápido, ligero y no necesita un cliente binario. Incluso, pueden obtener acceso a los datos sin ningún tipo de software especial de ayuda. 
  
- +===== Implementación ===== 
-Proceso de compilación +==== Compilación ====
 <code> <code>
-root@linux# wget 'http://www.mathias-kettner.de/download/mk-livestatus-1.1.2.tar.gz' +root@linux# wget 'http://www.mathias-kettner.de/download/mk-livestatus-1.2.6p16.tar.gz' 
-root@linux# tar xzf mk-livestatus-1.1.2.tar.gz +root@linux# tar xzf mk-livestatus-1.2.6p16.tar.gz 
-root@linux# cd mk-livestatus-1.1.2+root@linux# cd mk-livestatus-1.2.6p16
 root@linux# root@linux#
-root@linux# ./configure+root@linux# ./configure --with-nagios4
 checking for a BSD-compatible install... /usr/bin/install -c checking for a BSD-compatible install... /usr/bin/install -c
 checking whether build environment is sane... yes checking whether build environment is sane... yes
Línea 73: Línea 71:
 root@linux# make install root@linux# make install
 Making install in src Making install in src
-make[1]: Entering directory `/d/nagvis-dev/src/mk-livestatus-1.1.2/src' +make[1]: Entering directory `/d/nagvis-dev/src/mk-livestatus-1.2.6p16/src' 
-make[2]: Entering directory `/d/nagvis-dev/src/mk-livestatus-1.1.2/src'+make[2]: Entering directory `/d/nagvis-dev/src/mk-livestatus-1.2.6p16/src'
 test -z "/usr/local/bin" || /bin/mkdir -p "/usr/local/bin" test -z "/usr/local/bin" || /bin/mkdir -p "/usr/local/bin"
   /usr/bin/install -c 'unixcat' '/usr/local/bin/unixcat'   /usr/bin/install -c 'unixcat' '/usr/local/bin/unixcat'
Línea 80: Línea 78:
  /usr/bin/install -c -m 644 'livestatus.so' '/usr/local/lib/mk-livestatus/livestatus.so'  /usr/bin/install -c -m 644 'livestatus.so' '/usr/local/lib/mk-livestatus/livestatus.so'
  ranlib '/usr/local/lib/mk-livestatus/livestatus.so'  ranlib '/usr/local/lib/mk-livestatus/livestatus.so'
-/bin/sh /d/nagvis-dev/src/mk-livestatus-1.1.2/install-sh -d /usr/local/lib/mk-livestatus+/bin/sh /d/nagvis-dev/src/mk-livestatus-1.2.6p16/install-sh -d /usr/local/lib/mk-livestatus
 /usr/bin/install -c livestatus.o /usr/local/lib/mk-livestatus /usr/bin/install -c livestatus.o /usr/local/lib/mk-livestatus
 rm -f /usr/local/lib/mk-livestatus/livestatus.so rm -f /usr/local/lib/mk-livestatus/livestatus.so
-make[2]: Leaving directory `/d/nagvis-dev/src/mk-livestatus-1.1.2/src' +make[2]: Leaving directory `/d/nagvis-dev/src/mk-livestatus-1.2.6p16/src' 
-make[1]: Leaving directory `/d/nagvis-dev/src/mk-livestatus-1.1.2/src' +make[1]: Leaving directory `/d/nagvis-dev/src/mk-livestatus-1.2.6p16/src' 
-make[1]: Entering directory `/d/nagvis-dev/src/mk-livestatus-1.1.2+make[1]: Entering directory `/d/nagvis-dev/src/mk-livestatus-1.2.6p16
-make[2]: Entering directory `/d/nagvis-dev/src/mk-livestatus-1.1.2'+make[2]: Entering directory `/d/nagvis-dev/src/mk-livestatus-1.2.6p16'
 make[2]: Nothing to be done for `install-exec-am'. make[2]: Nothing to be done for `install-exec-am'.
 make[2]: Nothing to be done for `install-data-am'. make[2]: Nothing to be done for `install-data-am'.
-make[2]: Leaving directory `/d/nagvis-dev/src/mk-livestatus-1.1.2+make[2]: Leaving directory `/d/nagvis-dev/src/mk-livestatus-1.2.6p16
-make[1]: Leaving directory `/d/nagvis-dev/src/mk-livestatus-1.1.2'+make[1]: Leaving directory `/d/nagvis-dev/src/mk-livestatus-1.2.6p16'
 </code> </code>
- 
- 
 Despues tenemos que especificar que Nagios cargue el archivo objeto compilado //livestatus.o//, para eso debemos agregar a nagios.cfg:  Despues tenemos que especificar que Nagios cargue el archivo objeto compilado //livestatus.o//, para eso debemos agregar a nagios.cfg: 
  
Línea 102: Línea 98:
  
 Y dentro del log de Nagios vamos a ver algo similar a esto  Y dentro del log de Nagios vamos a ver algo similar a esto 
- 
 <code> <code>
-[1256144866] livestatus: Version 1.1.2 initializing. Socket path: '/var/lib+[1256144866] livestatus: Version 1.2.6p16 initializing. Socket path: '/var/lib
 /nagios/rw/live' /nagios/rw/live'
 [1256144866] livestatus: Created UNIX control socket at /var/lib/nagios/rw/ [1256144866] livestatus: Created UNIX control socket at /var/lib/nagios/rw/
Línea 116: Línea 111:
 [1256144866] livestatus: Entering main loop, listening on UNIX socket [1256144866] livestatus: Entering main loop, listening on UNIX socket
 </code> </code>
- +==== Opciones y configuración del módulo ====
- +
-Opciones del módulo +
 ^Opción^Valor por default^Que significa^ ^Opción^Valor por default^Que significa^
 |debug|0|Set this to 1 in order to make Livestatus log each query it executes in nagios.log| |debug|0|Set this to 1 in order to make Livestatus log each query it executes in nagios.log|
Línea 131: Línea 123:
  
 Ejemplo de como agregar opciones Ejemplo de como agregar opciones
- 
 <code> <code>
 broker_module=/usr/local/lib/mk-livestatus/livestatus.o /var/run/nagios/rw/live debug=1 broker_module=/usr/local/lib/mk-livestatus/livestatus.o /var/run/nagios/rw/live debug=1
Línea 137: Línea 128:
  
 Ejemplo de como dejar MK Livestatus escuchando en un socket tcp para consultarlo por red, por ejemplo por un sistema de reportes al estilo Jasper Reports o alguna interfaz alternativa como Thruk. Ejemplo de como dejar MK Livestatus escuchando en un socket tcp para consultarlo por red, por ejemplo por un sistema de reportes al estilo Jasper Reports o alguna interfaz alternativa como Thruk.
- 
 <code> <code>
 service livestatus service livestatus
Línea 166: Línea 156:
 } }
 </code> </code>
 +===== Ejemplos =====
 +==== Python ====
 +=== livestatus ===
 +<code python>
 +#!/usr/bin/python
 +import os
 +import livestatus
  
 +try:
 +    socket_path = "unix:/usr/local/nagios/var/rw/live"
 +except:
 +    sys.exit(1)
 +
 +try:
 +   # Make a single connection for each query
 +   print "\nPerformance:"
 +   for key, value in livestatus.SingleSiteConnection(socket_path).query_row_assoc("GET status").items():
 +      print "%-30s: %s" % (key, value)
 +   print "\nHosts:"
 +   hosts = livestatus.SingleSiteConnection(socket_path).query_table("GET hosts\nColumns: name alias address")
 +   for name, alias, address in hosts:
 +      print "%-16s %-16s %s" % (name, address, alias)
 +
 +   # Do several queries in one connection
 +   conn = livestatus.SingleSiteConnection(socket_path)
 +   num_up = conn.query_value("GET hosts\nStats: hard_state = 0")
 +   print "\nHosts up: %d" % num_up
 +
 +   stats = conn.query_row(
 + "GET services\n"
 + "Stats: state = 0\n"
 + "Stats: state = 1\n"
 + "Stats: state = 2\n"
 + "Stats: state = 3\n")
 +   print "Service stats: %d/%d/%d/%d" % tuple(stats)
 +
 +   print "List of commands: %s" % \
 +      ", ".join(conn.query_column("GET commands\nColumns: name"))
 +
 +   print "Query error:"
 +   conn.query_value("GET hosts\nColumns: hirni")
 +
 +
 +except Exception, e: # livestatus.MKLivestatusException, e:
 +   print "Livestatus error: %s" % str(e)
 +</code>
 +=== Monitoring::Livestatus ===
 +API de Perl para acceder a datos Nagios e Icinga por medio de check_mk livestatus
 +<code perl>
 +use Monitoring::Livestatus;
 +    my $ml = Monitoring::Livestatus->new(
 +      socket => '/var/lib/livestatus/livestatus.sock'
 +    );
 +    my $hosts = $ml->selectall_arrayref("GET hosts");
 +</code>
 +== new ([ARGS]) ==
 +Creates an Monitoring::Livestatus object. new takes at least the socketpath. Arguments are in key-value pairs.
 +Crea el objeto Monitoring::Livestatus. Toma la ruta del socket.
 +^Argumentos^^
 +^socket|Ruta al socket UNIX de check_mk livestatus|
 +^server|Usar este servidor para una conexión TCP|
 +^peer|Camino alternativo al socket o servidor, si se usa el valor ':' va a ser usado servidor sino socket|
 +^name|Nombre para la conexión, default dirección socket/server|
 +^verbose|Modo verbose|
 +^line_seperator|Código ascii separador de líneas default 10, (newline)|
 +^column_seperator|Código ascii separador de columnas, defaults 0 (null byte)|
 +^list_seperator|Código ascii separador de listas, default 44 (comma)|
 +^host_service_seperator|Código ascii separador host/service, default 124 (pipe)|
 +^keepalive|keepalive. Default off|
 +^errors_are_fatal|Errores con mensaje de caída. Default: on|
 +^warnings|muestran advertencias en las consultas sin Columnas|
 +^timeout|Tiempo de espera general. Usado para conexión y consultas|
 +^query_timeout|set a query timeout. Used for retrieving querys, Default 60sec|
 +^connect_timeout|Tiempo de espera de conexión inicial. Por defecto 5 s|
 +== Limit ==
 +<code perl>
 +my $array_ref = $ml->selectcol_arrayref(
 +       "GET hosts\nColumns: name contacts",
 +       { Limit => "10,20" }
 +    );
 +</code>
 +==== Perl ====
 +=== Monitoring::Livestatus ===
 +<code perl>
 +#!/usr/bin/perl
 +use Monitoring::Livestatus;
 +
 +$filtergrp = 'NAGIOS_ARGENTINA';
 +
 +$ml = Monitoring::Livestatus->new(
 + socket => '/usr/local/nagios/var/rw/live'
 +);
 +
 +my $up = $ml->selectscalar_value("GET hosts\nFilter: host_groups >= $filtergrp\nStats: state = 0");
 +my $down = $ml->selectscalar_value("GET hosts\nFilter: host_groups >= $filtergrp\nStats: state = 1");
 +my $unknown = $ml->selectscalar_value("GET hosts\nFilter: host_groups >= $filtergrp\nStats: state = 2");
 +my $total = $up + $down + $unknown;
 +
 +print "$down\/$total \n";
 +</code>
manuales/nagios/capacitacion/mk_livestatus.1442599675.txt.gz · Última modificación: 2015/09/18 18:07 por cayu