Integrate Zabbix graphics into the operations platform

Source: Internet
Author: User

Today, the operation and maintenance of the platform to add a function, is to integrate the Zabbix picture into the CMDB platform, of course, if you want to display graphics very beautiful is not recommended to do so; After several blogs, I also write a summary of the document:


The main ideas are:

1. Find the URL of the Zabbix image.

2. Read all the contents of the URL to generate a JPG file.

3, traverse the picture directory to return the picture file to the front-end JS integration.


1, open Zabbix, find the path of the picture:


650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/86/F8/wKiom1fP2s6wZELDAAD6QwVTJGg398.png "title=" QQ picture 20160907171523.png "Width=" "height=" 258 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:600px;height:258px; " alt= "Wkiom1fp2s6wzeldaad6qwvtjgg398.png"/>


Http://192.168.63.216/zabbix/chart2.php?graphid=567&period=60&stime=20160907160153&updateProfile=1 &profileIdx=web.screens&profileIdx2=567&width=1224&sid=0afbe713bbeb0519&screenid=& curtime=1473237848932

* The key parameters we are going to get are

*graphid: Graphics IP.

*stime: Start time; default we are out of the current time.

*period: Length of time: in seconds.


2, we need to obtain is graphid only, so through the Zabbix_client module ID to get out, style and I wrote before the API management Zabbix consistent, you can see for yourself:

def get_graphid (self,hostid): data = {"Selectgraphs": ["Graphid", "name"], "filter": {"HostID": H Ostid}} ret = Self.zb.host.get (**data) return ret[0][' graphs ']


3. Generate JPG image files via incoming Graphid, script:

#!/usr/bin/env python# -*- coding: utf-8 -*-from . import app ,  jsonrpcimport utilimport json, tracebackimport datetimeimport cookielib,  Urllib2,urllibclass zabbix_api ():     def __init__ (self,url= "/HTTP/ 192.168.63.216/zabbix/index.php ", name=" Admin ", password=" Zabbix "):         self.url=url        self.name=name         self.passwd=password         #初始化的时候生成cookies          cookiejar = cookielib. Cookiejar ()         urlopener = urllib2.build_opener (urllib2. Httpcookieprocessor (Cookiejar))         values = {"name": Self.name, ' password ': self.passwd, ' autologin ': 1, ' Enter ': ' Sign in '}&Nbsp;       data = urllib.urlencode (values)          request = urllib2. Request (Url, data)         try:             urlopener.open (request,timeout=10)              self.urlOpener=urlOpener         except urllib2. httperror, e:            print e     def getgraph (self,url= "http://192.168.63.216/zabbix/chart2.php", values={' width ':  800,  ' height ': 200,  ' graphid ':  ' 564 ',  ' stime ':  ' ' 20160907090409 ',  ' period ':  3600},image_dir= "/tmp"):         data=urllib.urlencode (values)         request&nbSp;= urllib2. Request (Url,data)         url = self.urlopener.open (Request)         image = url.read ()          imagename= "%s/%s_%s.jpg"  %  (image_dir, values["Graphid"], values["Stime" ])         f=open (imagename, ' WB ')          f.write (image)         return  ' 1 ' if __name__  ==  "__main__":     graph = zabbix_api ()     values  = {' width ': 800,  ' height ': 200,  ' graphid ':  ' 564 ',  ' stime ':  ' 20160907090409 ',  ' period ':  3600}    graph. Getgraph ("http://192.168.63.216/zabbix/chart2.php", Values, "/tmp")

4, back-end program processing, return the results and the front-end combination of the graphics loaded into the HTML can:


JS Processing Request:

/* Click the Monitor button to get the monitoring data */

$ ("Tbody"). On (' click ', '. Monitor-btn ', function () {    var id = $ (this). attr (' Data-id ')     var url =  "/getapi?method=" + "graph" + "&id=" +id     $.getjson (url,function (data) {      data = json.parse (data[ ' Result '])       console.log (data)       if  ( data[' Code ']==0) {          var str =  '             $.each (Data.result, function (n,value) {                 str += ' <br > '               })           console.log (str)            $ ("#graph"). HTML (str)           $ (' # Monitor '). Modal (' show ')               } Else{          swal ("Error",  data[' errmsg '],  " Error ")       }    })})


5. HTML page:


<!--monitoring View-

<div id= "Monitor"   class= "Modal fade text-center" > <div class= " Modal-dialog " style=" display: inline-block; width: 60%; " >    <div  class= "Modal-content" >       <div class= "Modal-header" >        <button type= " Button " class=" Close " data-dismiss=" modal " aria-label=" Close "><span aria-hidden=" True ">&times;</span></button>                 


6, the production effect, in the CMDB click Monitoring when jumping out of the relevant monitoring graphics for easy viewing:


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/86/F6/wKioL1fP3SXxOqS5AAFM1cZudd0780.png "title=" QQ picture 20160907172507.png "Width=" "height=" 272 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:800px;height:272px; " alt= "Wkiol1fp3sxxoqs5aafm1czudd0780.png"/>


Or there are operations engineers are accustomed to the generation of images sent in HTML to send to the mailbox is also can be counted, mainly the image has been generated by the subsequent operation is also very simple.


This article is from the "Little Luo" blog, please be sure to keep this source http://xiaoluoge.blog.51cto.com/9141967/1847406

Integrate Zabbix graphics into the operations platform

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.