项目作者: Prototype-X

项目描述 :
Network weathermap for Zabbix
高级语言: Python
项目地址: git://github.com/Prototype-X/Zabbix-Network-Weathermap.git
创建时间: 2016-04-09T15:21:07Z
项目社区:https://github.com/Prototype-X/Zabbix-Network-Weathermap

开源协议:GNU General Public License v3.0

下载


Zabbix-Network-Weathermap

Join the chat at https://gitter.im/Prototype-X/Zabbix-Network-Weathermap
Code Health

Network weathermap for Zabbix like Network Weathermap

Screenshot

map screenshot

Features

  • Get source data from Zabbix
  • Generate YAML config from Zabbix map
  • Create image with map in PNG format
  • Upload image to Zabbix
  • Support for map elements with the type: host, map, image

Requrements

  • Zabbix 3.4 (I dont check backward compability with Zabbix 3.0 - 3.2)
  • Python 3.4.3 and above
  • libs: Pillow, py-zabbix, ruamel.yaml

Install

  1. sudo apt-get install python3-pip python-pip python3-pil
  2. sudo pip3 install py-zabbix
  3. sudo pip3 install ruamel.yaml==0.14.12
  4. unzip Zabbix-Network-Weathermap.zip -d /opt
  5. chown -R zabbix:zabbix /opt/Zabbix-Network-Weathermap/*
  6. chmod a+x /opt/Zabbix-Network-Weathermap/starter.py
  7. chmod a+x /opt/Zabbix-Network-Weathermap/weathermap.py
  8. cp /opt/Zabbix-Network-Weathermap/template/userparameter_weathermap.conf /etc/zabbix/zabbix_agentd.d/
  • Copy /template/userparemeter_weathermap.conf to /etc/zabbix/zabbix_agentd.d/ and reload zabbix-agent
  • Import template /template/weathermap.xml to zabbix
  • Add Template Weathermap to host where use zabbix agent (for example use host zabbix server)
  • Create new user with permissions Zabbix Admin
  • User must have read-only or read-write access to hosts and hosts groups present in map
  • Go to Zabbix -> Configuration -> Template Weathermap -> Macros:

    {$SCANFILE} - When map config exist. If you change map remove host or change position host, configuration will be updated in accordance with changes on the map.

    {$SCANMAP} - First time scan map, config file not exist. Create file with map configuration.

    {$UPDATE} - Only create image, like old style Network Weathermap.

    {$UPLOAD} - Create and upload image to Zabbix.

  • Check Zabbix -> Configuration -> Hosts -> Host with Weathermap template -> Applications -> Weathermap -> Items -> Status

  • Create file with map configuration:

    1. weathermap.py -s mapname1 mapnameN -z http://zabbix.example.com -l admin -p admin

    OR

    Zabbix -> Template Weathermap -> Macros -> {$SCANMAP} -> Value

  • Open file /opt/Zabbix-Network-Weathermap/mapcfgs/mapname1.yaml and set hostname and itemin, itemout. If you set visible name, then use visible name instead hostname.

    1. link-1:
    2. node1: node-Router
    3. node2: node-Switch
    4. name1: R1
    5. name2: SW1
    6. width: 15
    7. hostname: Router
    8. #itemin/itemout = item key
    9. itemin: ifHCInOctets[ge-0/0/0]
    10. itemout: ifHCOutOctets[ge-0/0/0]
  • Create map image and upload it to Zabbix:

    1. weathermap.py -m mapname1.yaml -u

    OR

    Zabbix -> Template Weathermap -> Macros -> {$UPLOAD} -> Value

  • Set Zabbix -> Monitoring -> Maps -> mapname1 -> Properties -> Background image -> mapname1

Scripts note

Default path:

/opt/Zabbix-Network-Weathermap/mapcfgs - map config dir

/opt/Zabbix-Network-Weathermap/mapimgs - map images dir

/opt/Zabbix-Network-Weathermap/icons - map icons dir

  1. usage: weathermap.py [-v] [-h] [-d] [-m MAP [MAP ...]] [-i IMG] [-u] [-c CFG] [-s SCAN [SCAN ...]] [-f]
  2. [-z ZABBIX] [-l LOGIN] [-p PWD]
  3. Network weathermap for Zabbix
  4. optional arguments:
  5. -v, --version show version
  6. -h, --help show help
  7. -d, --debug Enable debug mode
  8. -m MAP [MAP ..], --map MAP [MAP ..] Config file names
  9. -i IMG, --img IMG Image path
  10. -u, --upload Image upload to zabbix
  11. -c CFG, --cfg CFG Config path
  12. -s SCAN [SCAN ..], --scan SCAN [SCAN ..] Map names in Zabbix
  13. -f, --file Zabbix authentication from map config file
  14. -z ZABBIX, --zabbix ZABBIX Zabbix server url
  15. -l LOGIN, --login LOGIN Login
  16. -p PWD, --pwd PWD Password
  17. # Examples:
  18. # When map config exist. If you change map remove host or change position host,
  19. # configuration will be updated in accordance with changes on the map.
  20. weathermap.py -s mapname1 mapnameN -f
  21. # First time scan map, config file not exist. Create file with map configuration.
  22. weathermap.py -s mapname1 mapnameN -z http://zabbix.example.ru -l login -p password
  23. # Only create image, like old style Network Weathermap.
  24. weathermap.py -m mapname1.yaml mapnameN.yaml -i /var/www/weather
  25. # Create and upload image to Zabbix.
  26. weathermap.py -m mapname1.yaml mapnameN.yaml -u

starter.py run weathermap.py and return execution time.

For auto update image or rescan map you can use cron, systemd or Template Weathermap.

Map config

  1. %YAML 1.2
  2. ---
  3. map:
  4. name: mapname1
  5. bgcolor: '' #background RGB color, default transparent
  6. fontsize: 10
  7. width: 1200
  8. height: 800
  9. zabbix:
  10. url: http://zabbix.example.com
  11. login: admin
  12. password: admin
  13. table: # show legend and date time
  14. show: true
  15. x: 1100
  16. y: 100
  17. palette: # RGB color arrow
  18. - '#908C8C'
  19. - '#FFFFFF'
  20. - '#8000FF'
  21. - '#0000FF'
  22. - '#00EAEA'
  23. - '#00FF00'
  24. - '#FFFF00'
  25. - '#FF9933'
  26. - '#FF0000'
  27. link: # default settings link
  28. bandwidth: 100 # in Mbits/s
  29. width: 10 # width arrow in pixels
  30. node-Router:
  31. name: Символы # Get from Zabbix
  32. label: R1 # For old style Network Weathermap, draw label
  33. icon: Router64.png # For old style Network Weathermap, draw icon, if path not exist, use defaults
  34. x: 625
  35. y: 225
  36. node-Router2:
  37. name: ''
  38. label: R2
  39. icon: Router64.png
  40. x: 625
  41. y: 225
  42. node-Switch:
  43. name: ''
  44. label: SW1
  45. icon: Switch64.png
  46. x: 75
  47. y: 375
  48. node-Switch2:
  49. name: ''
  50. label: SW2
  51. icon: Switch64.png
  52. x: 75
  53. y: 375
  54. link-1:
  55. node1: node-Router
  56. node2: node-Switch
  57. name1: '' # For human readability, get from zabbix
  58. name2: '' # For human readability, get from zabbix
  59. width: 15 # Override default settings in link
  60. hostname: Router
  61. itemin: ifHCInOctets[ge-0/0/0]
  62. itemout: ifHCOutOctets[ge-0/0/0]
  63. link-2:
  64. node1: node-Router2
  65. node2: node-Switch2
  66. name1: ''
  67. name2: ''
  68. bandwidth: 1000 # Override default settings in link
  69. hostname: Router2
  70. itemin: ifHCInOctets[ge-0/0/1]
  71. itemout: ifHCOutOctets[ge-0/0/1]
  72. ...

Option copy type bool, copy link and nodes in new config, when link and nodes not exist in zabbix map

  1. link-lyonlz7x:
  2. node1: node-nridx7c0
  3. node2: node-uwf443jw
  4. name1: net1
  5. name2: net2
  6. copy: true
  7. hostname: R10
  8. itemin: ifHCOutOctets[1/6]
  9. itemout: ifHCInOctets[1/6]

Notice

Zabbix 3.4.x do not refresh background image on map. FIX!

Zabbix API performance is low. Zabbix agent run weathermap.py. Weathermap.py can be terminated by timeout, set in
zabbix_agentd.conf.

Decision:

  1. Increase the timeout for example: zabbix_agentd.conf set Timeout=10

  2. One item to one map in Template Weathermap

  3. Use cron to run the scripts

If you need convert from old style config to YAML format, use converter.py

  1. user@pc:~$ converter.py /path-to-old-style-cfg/map.cfg
  2. user@pc:~$ ls /path-to-old-style-cfg
  3. map.cfg
  4. map.yaml

For a better look of map, set the link type a dot and color like background.

Gitter