manuales:nagios:capacitacion:mk_livestatus
Diferencias
Muestra las diferencias entre dos versiones de la página.
Ambos lados, revisión anteriorRevisión previa | Próxima revisiónAmbos lados, revisión siguiente | ||
manuales:nagios:capacitacion:mk_livestatus [2015/10/16 15:09] – cayu | manuales:nagios:capacitacion:mk_livestatus [2015/10/16 17:53] – cayu | ||
---|---|---|---|
Línea 156: | Línea 156: | ||
} | } | ||
</ | </ | ||
+ | ===== Ejemplos ===== | ||
+ | <code python> | ||
+ | # | ||
+ | # -*- encoding: utf-8; py-indent-offset: | ||
+ | # +------------------------------------------------------------------+ | ||
+ | # | ____ _ | ||
+ | # | / ___| |__ | ||
+ | # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / | | ||
+ | # | | |___| | | | __/ (__| < | ||
+ | # | \____|_| |_|\___|\___|_|\_\___|_| | ||
+ | # | | | ||
+ | # | Copyright Mathias Kettner 2013 | ||
+ | # +------------------------------------------------------------------+ | ||
+ | # | ||
+ | # This file is part of Check_MK. | ||
+ | # The official homepage is at http:// | ||
+ | # | ||
+ | # check_mk is free software; | ||
+ | # under the terms of the GNU General Public License | ||
+ | # the Free Software Foundation in version 2. check_mk is distributed | ||
+ | # in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
+ | # out even the implied warranty of MERCHANTABILITY | ||
+ | # PARTICULAR PURPOSE. See the GNU General Public License for more de- | ||
+ | # ails. You should have received | ||
+ | # License along with GNU Make; see the file COPYING. | ||
+ | # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, | ||
+ | # Boston, MA 02110-1301 USA. | ||
+ | import os | ||
+ | import livestatus | ||
+ | |||
+ | try: | ||
+ | # omd_root = os.getenv(" | ||
+ | socket_path = " | ||
+ | except: | ||
+ | sys.stderr.write(" | ||
+ | sys.stderr.write(" | ||
+ | sys.stderr.write(" | ||
+ | sys.exit(1) | ||
+ | |||
+ | try: | ||
+ | # Make a single connection for each query | ||
+ | print " | ||
+ | for key, value in livestatus.SingleSiteConnection(socket_path).query_row_assoc(" | ||
+ | print " | ||
+ | print " | ||
+ | hosts = livestatus.SingleSiteConnection(socket_path).query_table(" | ||
+ | for name, alias, address in hosts: | ||
+ | print "%-16s %-16s %s" % (name, address, alias) | ||
+ | |||
+ | # Do several queries in one connection | ||
+ | conn = livestatus.SingleSiteConnection(socket_path) | ||
+ | | ||
+ | print " | ||
+ | |||
+ | stats = conn.query_row( | ||
+ | "GET services\n" | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | print " | ||
+ | |||
+ | print "List of commands: %s" % \ | ||
+ | ", " | ||
+ | |||
+ | print "Query error:" | ||
+ | | ||
+ | |||
+ | |||
+ | except Exception, e: # livestatus.MKLivestatusException, | ||
+ | print " | ||
+ | </ |
manuales/nagios/capacitacion/mk_livestatus.txt · Última modificación: 2016/03/21 18:49 por cayu