zabbix conference 2012 miracle takanori suzuki final

Upload: lexcyr

Post on 14-Apr-2018

230 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/29/2019 Zabbix Conference 2012 Miracle Takanori Suzuki FINAL

    1/22

    How to extend Zabbix

    Takanori Suzuki

  • 7/29/2019 Zabbix Conference 2012 Miracle Takanori Suzuki FINAL

    2/22

    Introduction

    2

    Takanori Suzuki (irc: tsuzuki)Member of Zabbix-JP, Zabbix community in

    Japan.

    Working at MIRACLE LINUX corporation.Making some Zabbix patches and

    extensions.

    Non-stop, dynamically reloading DebugLeveland LogSlowQueries

    Multiple Zabbix active agent monitoring support

    Windows Eventing 6.0 support in Win2008

  • 7/29/2019 Zabbix Conference 2012 Miracle Takanori Suzuki FINAL

    3/22

    There are several ways toextend

    3

    Using Zabbix APIUsing Zabbix Protocol (get and sender)

    Changing Zabbix Server code

    Changing Zabbix Agent code

  • 7/29/2019 Zabbix Conference 2012 Miracle Takanori Suzuki FINAL

    4/22

    Using Zabbix API

    4

    It`s well known, so I skip theexplanation.

    Zabbix API Reference

    URL:http://www.zabbix.com/documentation/2.0/manual/appendix/api/api

    Functions

    Get, create, delete, update are supportedon hosts, items, triggers, actions and manyother objects.

  • 7/29/2019 Zabbix Conference 2012 Miracle Takanori Suzuki FINAL

    5/22

    Using Zabbix Protocol(get, sender and agent active)

    5

    If we want to send or get data to Zabbix,we can use Zabbix protocols.

    Zabbix get protocol

    Zabbix Sender protocolZabbix Agent (Active) protocol

  • 7/29/2019 Zabbix Conference 2012 Miracle Takanori Suzuki FINAL

    6/22

    Zabbix get protocol

    6

    Just sending key character data to10050 port

    $ telnet 127.0.0.1 10050Trying 127.0.0.1...

    Connected to localhost (127.0.0.1).Escape character is '^]'.agent.versionZBXD2.0.1Connection closed by foreign host.

  • 7/29/2019 Zabbix Conference 2012 Miracle Takanori Suzuki FINAL

    7/22

    Zabbix get protocol

    7

    Data is returned with header ZBXD\1and the following data length.

    Z B X D 0x01

    each square is 1Byte

    length of result data(unsigned 64bit LE)header

    2 . 0 . 1

    result data

    protocol version

  • 7/29/2019 Zabbix Conference 2012 Miracle Takanori Suzuki FINAL

    8/22

    Zabbix get protocol library

    8

    I made Zabbix get protocol class toPython library "zbxpy".https://github.com/BlueSkyDetector/zbxpy

    >>> import zbxpy>>> zbx_get = zbxpy.ZabbixGet(u'127.0.0.1')>>> zbx_get.request_key = "agent.version>>> print zbx_get.get()2.0.1

  • 7/29/2019 Zabbix Conference 2012 Miracle Takanori Suzuki FINAL

    9/22

    Zabbix get protocol example

    9

    DemoBy zbxpy, Python program can get data

    directly from Zabbix Agent.

  • 7/29/2019 Zabbix Conference 2012 Miracle Takanori Suzuki FINAL

    10/22

    Zabbix sender and active agentprotocol

    10

    data format is JSON with header.

  • 7/29/2019 Zabbix Conference 2012 Miracle Takanori Suzuki FINAL

    11/22

    Zabbix sender and active agentprotocol

    11

    JSON data format (send data)

    {"data":

    [

    { "host":"HostA","value":"sent data","key":"AppX_Logger"

    }],

    "request":"sender data"

  • 7/29/2019 Zabbix Conference 2012 Miracle Takanori Suzuki FINAL

    12/22

    Zabbix sender and active agentprotocol

    12

    JSON data format (receive data)

    {"response":"success","info":"Processed 2 Failed 0 Total 2 Seconds spent

    0.000103"}

  • 7/29/2019 Zabbix Conference 2012 Miracle Takanori Suzuki FINAL

    13/22

    Zabbix sender and active agentprotocol library

    13

    I made Zabbix sender protocol class toPython library "zbxpy".https://github.com/BlueSkyDetector/zbxpy

    >>> import zbxpy>>> sender = zbxpy.ZabbixSender(u'127.0.0.1')>>> for num in range(0, 2):... sender.add_data(u'HostA', u'AppX_Logger', u'sentdata ' + str(num))...>>> res = sender.send()

    >>> print sender.send_dataZBXD{"data":[{"host":"HostA","value":"sent data 0","key":"AppX_Logger"},{"host":"HostA","value":"sent data 1","key":"AppX_Logger"}],"request":"sender data"}

    >>> print resZBXDW{

    "response":"success","info":"Processed 2 Failed 0 Total 2 Seconds spent 0.034930"}

  • 7/29/2019 Zabbix Conference 2012 Miracle Takanori Suzuki FINAL

    14/22

    Zabbix sender and active agentprotocol example

    14

    DemoBy zbxpy, Python program can send data

    directly from the program to Zabbix Server.

  • 7/29/2019 Zabbix Conference 2012 Miracle Takanori Suzuki FINAL

    15/22

    Extend in Zabbix Server side

    15

    Zabbix Server consists from some kindof processes.

    We can add new features by adding

    new code to each process code.

  • 7/29/2019 Zabbix Conference 2012 Miracle Takanori Suzuki FINAL

    16/22

    Extend in Zabbix Server side

    16

    ArchitectureZabbix Web

    frontend

    on Apache

    (PHP)

    Zabbix

    Server

    (C lang)

    Database

    Zabbix Server

    watchdog (parent process)

    managing processes

    config syncer poller

    trapper

    poller

    (unreachable)

    pingerhousekeeper

    timer

    http poller

    db syncer poller (IPMI)

    selfmon

    monitoring processes

    alerting processes

    alerter escalator

    distributed monitoring processes

    node watcher proxy poller

    discoverer

    discovering processes

  • 7/29/2019 Zabbix Conference 2012 Miracle Takanori Suzuki FINAL

    17/22

    Extend in Zabbix Server side

    17

    For example, "db syncer" process stores

    history data to database.

    Zabbix Server

    (C lang)

    Zabbix Server

    watchdog (parent process)

    managing processes

    config syncer housekeeperdb syncer selfmon

    Writing data

    to database

  • 7/29/2019 Zabbix Conference 2012 Miracle Takanori Suzuki FINAL

    18/22

    Extending Zabbix Server example

    18

    By changing "db syncer" code, we canstore the history data to other things,like NoSQL.

  • 7/29/2019 Zabbix Conference 2012 Miracle Takanori Suzuki FINAL

    19/22

    Extend in Zabbix Agent side

    19

    ArchitectureZabbix Agent

    main process (parent process)

    collector active checkslistener

    listener

    listener

  • 7/29/2019 Zabbix Conference 2012 Miracle Takanori Suzuki FINAL

    20/22

    Extending Zabbix Agent example

    20

    I made a PoC patch, which addsmultiple "active checks" process toZabbix Agent to support multiple server

    in Active Checks.https://support.zabbix.com/browse/ZBXNEXT-584

    Its already merged after Zabbix 1.8.12 and

    2.0RC3.

  • 7/29/2019 Zabbix Conference 2012 Miracle Takanori Suzuki FINAL

    21/22

    Extending Zabbix Agent example

    21

    Before

    Zabbix Agent

    main process (parent process)

    collectoractive

    checkslistener

    listener

    listener

    After

    Zabbix Agent

    main process (parent process)

    collectoractive

    checkslistener

    listener

    listener

    active

    checks

    active

    checks

  • 7/29/2019 Zabbix Conference 2012 Miracle Takanori Suzuki FINAL

    22/22