Ad Widget

Collapse

Using PHP Network WeatherMap with Zabbix

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Using PHP Network WeatherMap with Zabbix

    Hello,

    I just start to use Zabbix few weeks ago and I'm really impressed by the product philosophy and possibilities...

    I'm an old nagios user and several things I actually use with nagios or cacti are missing.

    First one was Network Weather Map (www.network-weathermap.com) integration.

    So I made a datasource plugins in order to retrieve item value from zabbix history and use it in network weather map :

    The Target syntax is : zabbix:itemid_of_IN_value:temid_of_OUT_value


    You need to write down the itemid of each item you want to integrate with. A little bit anoying, but that's working !

    Also The plugin use only History_uint table for retreiving data.


    /weathermap/lib/datasources/WeatherMapDataSource_zabbix.php
    Code:
    <?php
    // Zabbix Pluggable datasource for PHP Weathermap 0.9
    // - read a pair of values from a database, and return it
    // Actually the plugin look only in history_uint table
    // TARGET zabbix:in:out
    
    class WeatherMapDataSource_zabbix extends WeatherMapDataSource {
    
            function Init(&$map)
            {
                    if(! function_exists("mysql_real_escape_string") ) return FALSE;
                    if(! function_exists("mysql_connect") ) return FALSE;
    
                    return(TRUE);
            }
    
            function Recognise($targetstring)
            {
    
             if(preg_match("/^zabbix:([\-a-zA-Z0-9_]+):([\-a-zA-Z0-9_]+)$/",$targetstring,$matches))
    
                    {
                            return TRUE;
                    }
                    else
                    {
                            return FALSE;
                    }
            }
    
            function ReadData($targetstring, &$map, &$item)
            {
                    $data[IN] = NULL;
                    $data[OUT] = NULL;
                    $data_time = 0;
    
                    if(preg_match("/^zabbix:([\-a-zA-Z0-9_]+):([\-a-zA-Z0-9_]+)$/",$targetstring,$matches))
                    {
                            $database_user = $map->get_hint('zabbix_dbuser');
                            $database_pass = $map->get_hint('zabbix_dbpass');
                            $database_name = $map->get_hint('zabbix_dbname');
                            $database_host = $map->get_hint('zabbix_dbhost');
    
                            $raw_in = mysql_real_escape_string($matches[1]);
                            $raw_out= mysql_real_escape_string($matches[2]);
    
                            debug ("Found for IN Value :  $raw_in \n");
                            debug ("Found for OUT Value :  $raw_out \n");
    
                            $SQL_IN = "select value from history_uint where itemid=$raw_in order by clock desc limit 1";
                            $SQL_OUT = "select value,clock from history_uint where itemid=$raw_out order by clock desc limit 1";
                            if(mysql_connect($database_host,$database_user,$database_pass))
                            {
                                    if(mysql_select_db($database_name))
                                    {
                                            $result_IN = mysql_query($SQL_IN);
                                            if (!$result_IN)
                                            {
                                                warn("Zabbix ReadData: Invalid query for IN Value: " . mysql_error()."\n");
                                            }
                                            else
                                            {
                                                    $row_IN = mysql_fetch_assoc($result_IN);
                                                    $data[IN] = $row_IN['value'];
                                            }
                                            $result_OUT = mysql_query($SQL_OUT);
                                            if (!$result_OUT)
                                            {
                                                warn("Zabbix ReadData: Invalid query for OUT Value: " . mysql_error()."\n");
                                            }
                                            else
                                            {
                                                    $row_OUT = mysql_fetch_assoc($result_OUT);
                                                    $data[OUT] = $row_OUT['value'];
                                                    $data_time = $row_OUT['clock'];
                                            }
    
    
    
                                    }
    
                                    else
                                    {
                                            warn("Zabbix ReadData: failed to select database ($database_name): ".mysql_error()."\n");
                                    }
                            }
                            else
                            {
                                    warn("Zabbix ReadData: failed to connect to database server: ".mysql_error()."\n");
                            }
    
                    //      $data_time = now();
                    }
    
    
                    debug ("RRD ReadData: Returning (".($data[IN]===NULL?'NULL':$data[IN]).",".($data[OUT]===NULL?'NULL':$data[IN]).",$data_time)\n");
    
                    return( array($data[IN], $data[OUT], $data_time) );
            }
    }
    ?>

    #2
    Looks interesting. Can you post some screen shots?
    Unofficial Zabbix Expert
    Blog, Corporate Site

    Comment


      #3
      Here a small screenshot (French Translated)



      Actually it's part of an zabbix screen...

      Bandwith Update occurs every 60s.

      Comment


        #4
        Hi tungsten

        Can you explain deeper how you make weathermap working with zabbix , I am really interested in
        I download it, but I still confused how it is working with zabbix

        Comment


          #5
          +1

          I'm also interessting to use it,
          But where you say what data you want to "Graph" ??

          Regards,
          Pierre (From France :-)
          P.Hoffmann
          System & Network Admin.
          __________________________
          Zabbix version 1.8.1
          Hosts monitored 1300
          OS Novell SLES 10 SP2
          __________________________

          Comment


            #6
            Ok I will try to write a complete tutorial for that ...

            Regards,

            Tungsten (From France)

            Comment


              #7
              Interesting post!
              What version of ZABBIX you running on?

              Cheers,
              BEE

              Comment


                #8
                I'm using the 1.45 Version on a Jeos Appliance.

                Comment


                  #9
                  Hi, I write Network Weathermap... at some point in the next couple of versions there will be new functions for data source plugins so that they can supply lists of possible data sources to the editor. At that stage, you should be able to pick interfaces/whatever from Zabbix in the editor, and it will do the right thing to fill in the target, infourl etc.

                  Thanks Tungsten for extending Weathermap's reach, too

                  Comment


                    #10
                    Tungsten, many thanks for telling us about Network WeatherMap...and for making that data-source for zabbix, it is a really good thing to complete Zabbix maps.
                    Howie, I am glad that you joined Zabbix forum, and congrats for writing Network WeatherMap; I didn`t tryed to install it yet, but I will sure do; Extending functionalities of your software to co-operate with zabbix which has a big user base will be a great thing for both "sides"
                    Last edited by theologu; 28-06-2008, 21:09.

                    Comment


                      #11
                      Tungsten, you said that your scrrenshot is part of a zabbix screen... how did you integrated the map generated by NWM into a zabbix screen?

                      Thanks

                      Comment


                        #12
                        I've started playing around with it and after some tinkering, I have a working weathermap. This adds an excellent visualization tool to ZABBIX, especially for complex networks.

                        A very quick HOWTO:

                        1) Install php-weathermap somewhere.
                        2) Read the fine manual
                        3) Create a weathermap of the hosts you want to monitor.
                        4) Configure WeatherMapDataSource_zabbix.php (and put it in the right place at weathermap/lib/datasources - not in the ZABBIX directory).
                        5) To get the id's of the Items to put in the map, I've named all my traffic Items "Traffic..." so I ran the following MySQL query:

                        SELECT * FROM items i where description LIKE 'Traffic%';

                        this gets me the itemid I need to put into the weathermap configuration file. Note that I got error messages around lines 44 and 45 of the php file because my root MySQL user has a password. I guess these are for debugging purposes. I've also hardcoded the host, username and password of the database at around line 52 and hardcoded the datbase name at line 54. The variables didn't seem to work. Also note that the Items must be Integers or the script won't work.

                        6) Create the weathermap using "php ./weathermap --config mymap.conf"
                        7) Enjoy
                        8) If you want your map to auto-update itself, create a cron job or a Windows Scheduled Task to run the command at step 6)

                        Comment


                          #13
                          Quickly the SQL syntax to get itemid with the hostname and the description field to make the itemid search easier

                          SELECT hosts.host, items.description, items.itemid
                          FROM items, hosts WHERE items.hostid = hosts.hostid AND hosts.host LIKE '%PATTERN%'

                          Hope this help for people who are not easy with mysql
                          Last edited by pcamelio; 11-07-2008, 08:48.

                          Comment


                            #14
                            mouse over graphs ?

                            I have used PHP weather map before and really like the fucntionality of mouse over java script (libover ?) with rrd and the pop up graphs. has anyone thought about this or started working on it for zabbix ?

                            Comment


                              #15
                              Hi all!

                              I've some difficulty to integrate network weathermap in zabbix, i find the itemid but i don't know how use it in network weathermap.
                              Anybody can help me or have a tutorial please?

                              Thanks

                              Comment

                              Announcement

                              Collapse
                              No announcement yet.
                              Working...
                              X