Ad Widget

Collapse

Zabbix generated reports to e-mail

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Peteris
    Member
    • Feb 2010
    • 89

    #1

    Zabbix generated reports to e-mail

    Hi,

    I'm wondering if it's possible to get daily reports from Zabbix which represents information about certain values (current, avg etc.) that I'm interested in?

    For example, I would like to receive daily report about certain server disk usage every morning at 10 am.

    Does Zabbix provides this function or is there any way to do it?
  • Peteris
    Member
    • Feb 2010
    • 89

    #2
    up!

    Is there no way to achieve it in Zabbix?

    Comment

    • low10sws6
      Member
      • Oct 2008
      • 44

      #3
      Zabbix Monthly Reports

      i've been creating a Zabbix Monthly Report thats sent from the zabbix interface PHP to PDF and Emailed to the users address

      in the attachment is an image of the pdf emailed to myself
      also had graphs exported and applied to the pdf but decided to keep it simple

      the only thing i have left is getting the percentage of the availability for each category


      SELECT COUNT(*) as cnt, MIN(clock) as minn, MAX(clock) as maxx FROM events WHERE objectid=26435 AND object=0 AND clock>=1291755180 AND clock<=1294433634;

      i believe this gets the problem events that occurred between a 30day time period

      now i just need the total events to get the percentage i believe.


      If i remember tomorrow i'll paste in some of the sql queries i used to generate this data
      Attached Files

      Comment

      • moo
        Junior Member
        • Aug 2010
        • 22

        #4
        low10sws6, I'd be very interested in this too! i'm looking for pretty much exactly the same thing

        Comment

        • Peteris
          Member
          • Feb 2010
          • 89

          #5
          It looks really nice, how do you put/format it in PDF?

          Thank you for sharing!

          Comment

          • low10sws6
            Member
            • Oct 2008
            • 44

            #6
            SQL Query

            This shows how i got the problem areas; some might not be used at this point but either was or will be. i lookup proxyid to get information

            you'll need fpdf -> http://www.fpdf.org/

            and the includes bellow to make this work easier
            PHP Code:
            <?php
            require('fpdf.php');
            require_once(
            'include/config.inc.php');
            require_once(
            'include/triggers.inc.php');
            require_once(
            'include/hosts.inc.php');
            require_once(
            'include/reports.inc.php');
            Problematic Areas
            PHP Code:
            ////Problematic Areas

                    
            $available_hosts get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY);
                    
            $available_triggers get_accessible_triggers(PERM_READ_ONLY, array());
                    
            $scripts_by_hosts CScript::getScriptsByHosts($available_hosts);

                    
            $triggers = array();
                    
            $triggerids = array();

                    
            $sql 'SELECT h.host as HOSTNAME, t.description as DESCRIPTION,'.
                                            
            ' FROM_UNIXTIME(MAX(t.lastchange)) as LAST_CHANGED, count(distinct e.eventid) as Events_Occurred '.
                                    
            ' FROM hosts h, triggers t, functions f, items i, events e'.
                                    
            ' WHERE h.hostid = i.hostid '.
                                            
            ' and h.proxy_hostid = '.$proxyid.
                                            
            ' and i.itemid = f.itemid '.
                                            
            ' and t.triggerid=f.triggerid '.
                                            
            ' and t.triggerid=e.objectid '.
                                            
            ' and e.object='.EVENT_OBJECT_TRIGGER.
                                            
            ' and e.clock>'.(time()-30*86400).
                                            
            ' and '.DBcondition('t.triggerid',$available_triggers).
                                            
            ' and '.DBin_node('t.triggerid').
                                            
            ' and t.description NOT LIKE "%Configuration%"'.
                                            
            ' and t.description NOT LIKE "%Collector%"'.
                                    
            ' GROUP BY h.host,t.triggerid,t.description,t.expression,t.priority '.
                                    
            ' ORDER BY Events_Occurred desc, h.host, t.description, t.triggerid';
                    
            $result=DBselect($sql100);


            $numrows mysql_numrows($result);

            //Initialize the 3 columns and the total
            $column_host "";
            $column_desc "";
            $column_change "";
            $column_events "";
            $alarmgen "";

            //For each row, add the field to the corresponding column
            while($row mysql_fetch_array($result))
            {
                
            $host $row["HOSTNAME"];
                
            $desc $row["DESCRIPTION"];
                
            $change $row["LAST_CHANGED"];
                
            $events $row["Events_Occurred"];

                
            $search "Adaptive Security Appliance";
                
            $replace "ASA";
                
            $desc str_replace($search$replace$desc);

                
            $search "{ITEM.LASTVALUE}";
                
            $replace "";
                
            $desc str_replace($search$replace$desc);

                
            $search "{HOSTNAME}";
                
            $replace "$host";
                
            $desc str_replace($search$replace$desc);


                
            $column_host $column_host.$host."\n";
                
            $column_desc $column_desc.$desc."\n";
                
            $column_change $column_change.$change."\n";
                
            $column_events $column_events.$events."\n";


            $alarmgen += $row["Events_Occurred"];


            create PDF

            PHP Code:
            $pdf->SetY($Y_Table_Position);
            $pdf->SetX(72);
            $pdf->MultiCell(40,4,$column_host,0); 
            Mail pdf

            HTML Code:
            #
            #//// Mail PDF to user
            #
            #
            // main header (multipart mandatory)
            #
            $headers = "From: ".$from.$eol;
            #
            $headers .= "MIME-Version: 1.0".$eol;
            #
            $headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol;
            #
            $headers .= "Content-Transfer-Encoding: 7bit".$eol;
            #
            $headers .= "This is a MIME encoded message.".$eol.$eol;
            #
            
            #
            // message
            #
            $headers .= "--".$separator.$eol;
            #
            $headers .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
            #
            $headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
            #
            $headers .= $message.$eol.$eol;
            #
            
            #
            // attachment
            #
            $headers .= "--".$separator.$eol;
            #
            $headers .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
            #
            $headers .= "Content-Transfer-Encoding: base64".$eol;
            #
            $headers .= "Content-Disposition: attachment".$eol.$eol;
            #
            $headers .= $attachment.$eol.$eol;
            #
            $headers .= "--".$separator."--".$eol;
            #
            
            #
            // send message
            #
            mail($to, $subject, "", $headers).$eol;
            #
            if you guys have any input, ideas, or questions let me know this an on going project feel free to express them

            I use OTRS for tickets in which i query otrs DB to get that info.

            Zabbix and a custom EXPECT script to gather running configs and their state with rsync to send the back the configs to the server

            if anyone knows how to get the availability percentage of a device let me know

            Comment

            • moo
              Junior Member
              • Aug 2010
              • 22

              #7
              Great stuff!!

              Many thanks for that! Will be having a play about with this asap ^_^

              Comment

              • kofeyh
                Junior Member
                • Jun 2010
                • 17

                #8
                If a little more detail on how this slots into Zabbix could be added, that would be awesome.

                Where do the PHP snippets go?

                Comment

                • osorio88
                  Junior Member
                  • Feb 2011
                  • 29

                  #9
                  Originally posted by low10sws6
                  PHP Code:
                  <?php
                  require('fpdf.php');
                  require_once(
                  'include/config.inc.php');
                  require_once(
                  'include/triggers.inc.php');
                  require_once(
                  'include/hosts.inc.php');
                  require_once(
                  'include/reports.inc.php');
                  Problematic Areas
                  PHP Code:
                  ////Problematic Areas

                          
                  $available_hosts get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY);
                          
                  $available_triggers get_accessible_triggers(PERM_READ_ONLY, array());
                          
                  $scripts_by_hosts CScript::getScriptsByHosts($available_hosts);

                          
                  $triggers = array();
                          
                  $triggerids = array();

                          
                  $sql 'SELECT h.host as HOSTNAME, t.description as DESCRIPTION,'.
                                                  
                  ' FROM_UNIXTIME(MAX(t.lastchange)) as LAST_CHANGED, count(distinct e.eventid) as Events_Occurred '.
                                          
                  ' FROM hosts h, triggers t, functions f, items i, events e'.
                                          
                  ' WHERE h.hostid = i.hostid '.
                                                  
                  ' and h.proxy_hostid = '.$proxyid.
                                                  
                  ' and i.itemid = f.itemid '.
                                                  
                  ' and t.triggerid=f.triggerid '.
                                                  
                  ' and t.triggerid=e.objectid '.
                                                  
                  ' and e.object='.EVENT_OBJECT_TRIGGER.
                                                  
                  ' and e.clock>'.(time()-30*86400).
                                                  
                  ' and '.DBcondition('t.triggerid',$available_triggers).
                                                  
                  ' and '.DBin_node('t.triggerid').
                                                  
                  ' and t.description NOT LIKE "%Configuration%"'.
                                                  
                  ' and t.description NOT LIKE "%Collector%"'.
                                          
                  ' GROUP BY h.host,t.triggerid,t.description,t.expression,t.priority '.
                                          
                  ' ORDER BY Events_Occurred desc, h.host, t.description, t.triggerid';
                          
                  $result=DBselect($sql100);


                  $numrows mysql_numrows($result);

                  //Initialize the 3 columns and the total
                  $column_host "";
                  $column_desc "";
                  $column_change "";
                  $column_events "";
                  $alarmgen "";

                  //For each row, add the field to the corresponding column
                  while($row mysql_fetch_array($result))
                  {
                      
                  $host $row["HOSTNAME"];
                      
                  $desc $row["DESCRIPTION"];
                      
                  $change $row["LAST_CHANGED"];
                      
                  $events $row["Events_Occurred"];

                      
                  $search "Adaptive Security Appliance";
                      
                  $replace "ASA";
                      
                  $desc str_replace($search$replace$desc);

                      
                  $search "{ITEM.LASTVALUE}";
                      
                  $replace "";
                      
                  $desc str_replace($search$replace$desc);

                      
                  $search "{HOSTNAME}";
                      
                  $replace "$host";
                      
                  $desc str_replace($search$replace$desc);


                      
                  $column_host $column_host.$host."\n";
                      
                  $column_desc $column_desc.$desc."\n";
                      
                  $column_change $column_change.$change."\n";
                      
                  $column_events $column_events.$events."\n";


                  $alarmgen += $row["Events_Occurred"];


                  create PDF

                  PHP Code:
                  $pdf->SetY($Y_Table_Position);
                  $pdf->SetX(72);
                  $pdf->MultiCell(40,4,$column_host,0); 
                  Mail pdf

                  HTML Code:
                  #
                  #//// Mail PDF to user
                  #
                  #
                  // main header (multipart mandatory)
                  #
                  $headers = "From: ".$from.$eol;
                  #
                  $headers .= "MIME-Version: 1.0".$eol;
                  #
                  $headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol;
                  #
                  $headers .= "Content-Transfer-Encoding: 7bit".$eol;
                  #
                  $headers .= "This is a MIME encoded message.".$eol.$eol;
                  #
                  
                  #
                  // message
                  #
                  $headers .= "--".$separator.$eol;
                  #
                  $headers .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
                  #
                  $headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
                  #
                  $headers .= $message.$eol.$eol;
                  #
                  
                  #
                  // attachment
                  #
                  $headers .= "--".$separator.$eol;
                  #
                  $headers .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
                  #
                  $headers .= "Content-Transfer-Encoding: base64".$eol;
                  #
                  $headers .= "Content-Disposition: attachment".$eol.$eol;
                  #
                  $headers .= $attachment.$eol.$eol;
                  #
                  $headers .= "--".$separator."--".$eol;
                  #
                  
                  #
                  // send message
                  #
                  mail($to, $subject, "", $headers).$eol;
                  #
                  All this code is just one file?. Could someone explain a little bit more this? this is interesting and I would like to use this kind of report.
                  Thanks.

                  Comment

                  • hahnium
                    Junior Member
                    Zabbix Certified Specialist
                    • Feb 2011
                    • 13

                    #10
                    We are also interested in this feature, and it would be great if it was integrated in Zabbix!

                    Comment

                    • daniel2009
                      Junior Member
                      • Aug 2011
                      • 5

                      #11
                      Is it topic still continue? I don't know how to configure this future, script, php script or something else?
                      Anybody can explain it to me?

                      Comment

                      • eric8x
                        Junior Member
                        • Dec 2011
                        • 1

                        #12
                        its great

                        Comment

                        • bimvis
                          Junior Member
                          • Sep 2013
                          • 5

                          #13
                          I also wanna know how to configure this. Is there any help possible?

                          Comment

                          Working...