Ad Widget

Collapse

Screens Cloning and easy upgrading

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sebelk
    Member
    • Nov 2007
    • 72

    #1

    Screens Cloning and easy upgrading

    Hi,

    Since a few weeks I am using zabbix. It's a great and powerful tool. But it lacks a important feature: Cloning Screen.

    The issue is General Overview is too ugly to daily work. So screen is for me the only way to use in a productive way. But with no cloning feature, it's hard to take advantage of Zabbix. (Is someone found a way to clone screen I'd glad to know how, altough I've read some approaches )

    So, please, please, please, consider add this feature for next release.

    Also, I think in the next release, and I hope that upgrade is not be a pain, please
  • Tenzer
    Senior Member
    • Nov 2007
    • 316

    #2
    I made a little command line PHP script to create new screens out of switch traffic graphs. Since there are 50 ports in the switches and we have several switches where I work, it would take to long time to create all the screens manually through the webinterface.

    Comment

    • sebelk
      Member
      • Nov 2007
      • 72

      #3
      Please, could you post it?

      Comment

      • Tenzer
        Senior Member
        • Nov 2007
        • 316

        #4
        Sure, here goes:
        PHP Code:
        #!/usr/bin/php
        <?
            # Check if a switch name is given, and save the name
            if(isset($_SERVER[argv][1]))
            {
                $sw_name = $_SERVER[argv][1];
            } else {
                echo "You haven't used the correct syntax.\nSyntax: ". $_SERVER[argv][0] ." <switch name> [port count (default 50)]\n";
                exit();
            }

            # Check if number of ports have been defined, or else set to default of 50
            if(isset($_SERVER[argv][2]))
            {
                $sw_ports = $_SERVER[argv][2];
            } else {
                $sw_ports = 50;
            }

            # MySQL database information
            $db_username = "zabbix";
            $db_hostname = "localhost";
            $db_password = "zabbix";
            $db_database = "zabbix";

            # Connect to the MySQL server and select the database
            $db_connection = mysql_connect($db_hostname, $db_username, $db_password);
            $db_connection = mysql_select_db($db_database, $db_connection);

            # Get the switchs ID from the database
            $data = mysql_query("SELECT hostid FROM hosts WHERE host = '$sw_name'");
            $sw_id = mysql_fetch_assoc($data);
            if(count($sw_id) == 0)
            {
                echo "The switch, $sw_name, was not found in the database.\n";
                exit();
            } else {
                $sw_id = $sw_id[hostid];
            }

            # Get a list of itemids for ifInOctets1-(port count), and put them in an array
            for($i = 1; $i <= $sw_ports; $i++)
            {
                $data = mysql_query("SELECT itemid FROM items WHERE hostid = '$sw_id' AND snmp_oid = '1.3.6.1.2.1.2.2.1.10.$i'");
                $data = mysql_fetch_assoc($data);
                $itemids[$i] = $data[itemid];
            }

            # Get a list of the graph ids and put them in an array
            foreach($itemids as &$id)
            {
                $data = mysql_query("SELECT graphid FROM graphs_items WHERE itemid = $id");
                $data = mysql_fetch_assoc($data);
                $id = $data[graphid];
            }

            # Calculate how many rows we need for the new screen
            $rows = ceil($sw_ports/2);

            # Find the id we should use for the new screen and create it
            $data = mysql_query("SELECT screenid FROM screens ORDER BY screenid DESC LIMIT 1");
            $data = mysql_fetch_assoc($data);
            $screenid = $data[screenid]+1;
            $data = mysql_query("INSERT INTO screens VALUES($screenid, '$sw_name', 2, $rows)");

            # Find the next id in the screens_items table, and start inserting the graphs
            $data = mysql_query("SELECT screenitemid FROM screens_items ORDER BY screenitemid DESC LIMIT 1");
            $data = mysql_fetch_assoc($data);
            $screenitemid = $data[screenitemid]+1;
            $x = 0;
            $y = 0;
            for($i = 1; $i <= $sw_ports; $i++)
            {
                $data = mysql_query("INSERT INTO screens_items VALUES($screenitemid, $screenid, 0, $itemids[$i], 500, 100, $x, $y, 0, 0, 0, 0, 0, 0, '')");
                $x++;
                $screenitemid++;
                if($x == 2)
                {
                    $x = 0;
                    $y++;
                }
            }

            # Update the table ids in order to not create problems for zabbix
            $data = mysql_query("SELECT screenid FROM screens ORDER BY screenid DESC LIMIT 1");
            $data = mysql_fetch_assoc($data);
            $screenid = $data[screenid]+1;
            $data = mysql_query("UPDATE ids SET nextid = $screenid WHERE table_name = 'screens'");

            $data = mysql_query("SELECT screenitemid FROM screens_items ORDER BY screenitemid DESC LIMIT 1");
            $data = mysql_fetch_assoc($data);
            $screenitemid = $data[screenitemid]+1;
            $data = mysql_query("UPDATE ids SET nextid = $screenitemid WHERE table_name = 'screens_items'");
        ?>
        The script is being used for HP Procurve switches which has been added using the XML template from the wiki, but you could modify the script to your needs.

        Comment

        • sebelk
          Member
          • Nov 2007
          • 72

          #5
          Thanks a lot, have you used this script in 1.4.2?

          Comment

          • Tenzer
            Senior Member
            • Nov 2007
            • 316

            #6
            Yup, that is what it was made for, I don't know how well it works with other versions though.

            Comment

            • sebelk
              Member
              • Nov 2007
              • 72

              #7
              Thanks Tenzer, don't want to kill me for stupid question, but where should a script like this be copied?

              Comment

              • Tenzer
                Senior Member
                • Nov 2007
                • 316

                #8
                You're welcome.
                The script is a command line PHP script, and it requires PHP installed on your server, and possible with the CLI module.
                It could probably easy be changed to a script to be called from a browser, since it is just a couple of variable names that needs to be changed, but then I would recommend you to get some security into this.

                Comment

                • sebelk
                  Member
                  • Nov 2007
                  • 72

                  #9
                  Thanks Tenzer,
                  I was using, and works fine!!

                  I've customized for other kind of graphics.

                  Again thanks!

                  Comment

                  Working...