Subversion-Projekte lars-tiefland.nagios-php

Revision

Revision 127 | Zur aktuellen Revision | Blame | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

<?php

    /**
     * @package nagios-php
     * @author Lars Tiefland <ltiefland@gmail.com>
     * @copyright 2013
     * @version $Rev: 128 $
     */

    // $Id: service.php 128 2013-01-12 17:41:35Z lars $

    /**
     * service
     * 
     * @package nagios-php
     * @author Lars Tiefland
     * @copyright 2012
     * @version $Rev: 128 $
     * @access public
     */
    class service
    {
        public $display_name;
        public $service_id;
        public $service_object_id;
        public $notes;
        public $notes_url;
        public $action_url;
        public $icon_image;
        public $icon_image_alt;
        public $current_state;
        public $status_update_time;
        public $current_check_attempt;
        public $max_check_attempts;

        /**
         * service::__construct()
         * 
         * @param mixed $id
         * @return
         */
        public function __construct( $id )
        {
            $sql = "SELECT
                    service_id,
                    display_name,
                    service_object_id,
                    notes,
                    notes_url,
                    action_url,
                    icon_image,
                    icon_image_alt,
                    current_state,
                    status_update_time,
                    current_check_attempt,
                    max_check_attempts
                FROM
                    services s
                JOIN
                    servicestatus ss
                ON
                    ss.service_object_id = s.service_object_id
                WHERE
                    service_id = $id
                AND
                    instance_id = " . $GLOBALS["cfg"]["instance"] . "
            ";
            $res = $GLOBALS["db"]->query( $sql );
            $row = $res->fetchRow();
            //$this->host_id=$row["host_id"];
            foreach ( $row as $feld => $wert )
            {
                $this->$feld = $wert;
            }
        }
        /**
         * service::getStatusList()
         * 
         * @return
         */
        public static function getStatusList()
        {
            $sql = "SELECT
                                        count(current_state) AS anz
                                FROM
                                        servicestatus
                                WHERE
                                        instance_id = " . $GLOBALS["cfg"]["instance"] . "
                                AND
                                        current_state = 0
                        ";
            $res = $GLOBALS["db"]->query( $sql );
            $row = $res->fetchRow();
            $rows["ok"] = $row["anz"];
            $sql = "SELECT
                                        count(current_state) AS anz
                                FROM
                                        servicestatus
                                WHERE
                                        instance_id = " . $GLOBALS["cfg"]["instance"] . "
                                AND
                                        current_state = 1
                        ";
            $res = $GLOBALS["db"]->query( $sql );
            $row = $res->fetchRow();
            $rows["warning"] = $row["anz"];
            $sql = "SELECT
                                        count(current_state) AS anz
                                FROM
                                        servicestatus
                                WHERE
                                        instance_id = " . $GLOBALS["cfg"]["instance"] . "
                                AND
                                        current_state = 2
                        ";
            $res = $GLOBALS["db"]->query( $sql );
            $row = $res->fetchRow();
            $rows["critical"] = $row["anz"];
            $sql = "SELECT
                                        count(current_state) AS anz
                                FROM
                                        servicestatus
                                WHERE
                                        instance_id = " . $GLOBALS["cfg"]["instance"] . "
                                AND
                                        current_state = 3
                        ";
            $res = $GLOBALS["db"]->query( $sql );
            $row = $res->fetchRow();
            $rows["unknown"] = $row["anz"];
            $rows["total"] = array_sum( $rows );
            return $rows;
        }
    }

?>