Extending Zabbix using the API
A real world example
                       October 1st, 2011
                       Zabbix Conference, Riga, Latvia

                       Walter Heck, Tribily.com
Introduction
                                                         2




  The zabbix API is still quite new, but already quite
powerful. This presentation will show you one of many
                uses for it. Be inspired!
Who am I?
                                                          3



• Walter Heck, 30 years old
• Ex-Delphi programmer
• Location independent
• MySQL Consultant for Open Query
• Narcoleptic
• Traveler / hitchhiker / couchsurfer / diver / hiker /
  geek / environmentalist / metalhead
Tribily
                                                  4



 •   Server monitoring as a service (SMaaS)
 •   Role = 1 or more templates
 •   Template is either an App, OS, or hardware
 •   Self-defined Restrictions
     •   Active only hosts
     •   1 User <=> 1Hostgroup <=> 1Usergroup
     •   Zabbix permissions read-only
     •   All writes done through Drupal module
Drupal module
                                                 5



• Custom module written in PHP, started from
  scratch
• Fully Open Source: http://github.com/tribily
•
Zabbix
                                                     6



• Currently 1.8.2, but API is young and buggy,
  imminent upgrade to 1.8.8
• Interfacing using PHP API class by Andrew Farley
• Only admin user has API permissions turned on
Structure
                                                                           7



•   Login first, PHP API will check
    // This logs into Zabbix, and returns FALSE if it fails

    return ZabbixAPI::login($API_url, $API_user, $API_pass);


•   Then execute your method
    $trigger = ZabbixAPI::fetch_array('trigger', 'get', $options)

       or drupal_set_message('Unable to get zabbix triggers: ' .

       serialize(ZabbixAPI::getLastError(), TRUE), DRUPAL_MSG_TYPE_ERR);
Module functionality - user
                                                   8



• Create zabbix user, usergroup and hostgroup on
  creation of drupal user
• Create hosts (no IP or DNS, status monitored)
• Assign templates based on roles
Module functionality – Admin
                                                      9



• Update actions text (hundreds of users, thousands
  of actions!)
• Configuration options
• Zabbix API credentials
Challenges
                                                          10



• Using older 1.8.2, so not everything works or is
  actually transparent, so lots of searching the zabbix
  frontend source
• Not everything is implemented
 • Sometimes delete and re-add works better then
    update
Future plans
                                                         11



• Eventually replace frontend altogether (unless it
  improves massively before that ;) ) and pull it into
  drupal
• Multiple users / usergroups / hostgroups per drupal
  user
• Daily / weekly / monthly reports
12




Questions / Feedback ?
The End!



http://tribily.com
walter@tribily.com
     @tribily

Using Zabbix API from Drupal

  • 1.
    Extending Zabbix usingthe API A real world example October 1st, 2011 Zabbix Conference, Riga, Latvia Walter Heck, Tribily.com
  • 2.
    Introduction 2 The zabbix API is still quite new, but already quite powerful. This presentation will show you one of many uses for it. Be inspired!
  • 3.
    Who am I? 3 • Walter Heck, 30 years old • Ex-Delphi programmer • Location independent • MySQL Consultant for Open Query • Narcoleptic • Traveler / hitchhiker / couchsurfer / diver / hiker / geek / environmentalist / metalhead
  • 4.
    Tribily 4 • Server monitoring as a service (SMaaS) • Role = 1 or more templates • Template is either an App, OS, or hardware • Self-defined Restrictions • Active only hosts • 1 User <=> 1Hostgroup <=> 1Usergroup • Zabbix permissions read-only • All writes done through Drupal module
  • 5.
    Drupal module 5 • Custom module written in PHP, started from scratch • Fully Open Source: http://github.com/tribily •
  • 6.
    Zabbix 6 • Currently 1.8.2, but API is young and buggy, imminent upgrade to 1.8.8 • Interfacing using PHP API class by Andrew Farley • Only admin user has API permissions turned on
  • 7.
    Structure 7 • Login first, PHP API will check // This logs into Zabbix, and returns FALSE if it fails return ZabbixAPI::login($API_url, $API_user, $API_pass); • Then execute your method $trigger = ZabbixAPI::fetch_array('trigger', 'get', $options) or drupal_set_message('Unable to get zabbix triggers: ' . serialize(ZabbixAPI::getLastError(), TRUE), DRUPAL_MSG_TYPE_ERR);
  • 8.
    Module functionality -user 8 • Create zabbix user, usergroup and hostgroup on creation of drupal user • Create hosts (no IP or DNS, status monitored) • Assign templates based on roles
  • 9.
    Module functionality –Admin 9 • Update actions text (hundreds of users, thousands of actions!) • Configuration options • Zabbix API credentials
  • 10.
    Challenges 10 • Using older 1.8.2, so not everything works or is actually transparent, so lots of searching the zabbix frontend source • Not everything is implemented • Sometimes delete and re-add works better then update
  • 11.
    Future plans 11 • Eventually replace frontend altogether (unless it improves massively before that ;) ) and pull it into drupal • Multiple users / usergroups / hostgroups per drupal user • Daily / weekly / monthly reports
  • 12.
  • 13.