Subversion-Projekte lars-tiefland.nagios-php

Revision

Revision 86 | Blame | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

<?php

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

    // $Id: host.php 115 2013-01-05 19:05:29Z lars $

    /**
     * host
     * 
     * @package nagios-php   
     * @author Lars Tiefland
     * @copyright 2012
     * @version $Rev: 115 $
     * @access public
     */
    class host
    {
        public $display_name;
        public $host_id;
        public $host_object_id;
        public $services;

        /**
         * host::__construct()
         * 
         * @param mixed $id
         * @return
         */
        public function __construct( $id, $is_host_object_id = false )
        {
            if ( $is_host_object_id )
            {
                $id_where = "host_object_id = $id";
            }
            else
            {
                $id_where = "host_id = $id";
            }
            $sql = "SELECT
                    host_id,
                    display_name,
                    host_object_id
                FROM
                    hosts
                WHERE
                    " . $id_where . "
                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;
            }
            $this->services = host::getHostServiceList( $id );
        }

        /**
         * host::getHostServiceList()
         * 
         * @param mixed $host_id
         * @return
         */
        public static function getHostServiceList( $host_id )
        {
            $sql = "SELECT
                    service_id
                FROM
                    services
                WHERE
                    host_object_id = $host_id
                AND
                    instance_id = " . $GLOBALS["cfg"]["instance"] . "
            ";
            $res = $GLOBALS["db"]->query( $sql );
            while ( $row = $res->fetchRow() )
            {
                $ret[] = new service( $row["service_id"] );
            }
            return $ret;
        }
        /**
         * host::getStatusList()
         * 
         * @return
         */
        public static function getStatusList()
        {
            $sql = "SELECT
                                        count(current_state) AS anz
                                FROM
                                        hoststatus
                                WHERE
                                        instance_id = " . $GLOBALS["cfg"]["instance"] . "
                                AND
                                        current_state = 0
                        ";
            $res = $GLOBALS["db"]->query( $sql );
            $row = $res->fetchRow();
            $rows["up"] = $row["anz"];
            $sql = "SELECT
                                        count(current_state) AS anz
                                FROM
                                        hoststatus
                                WHERE
                                        instance_id = " . $GLOBALS["cfg"]["instance"] . "
                                AND
                                        current_state = 1
                        ";
            $res = $GLOBALS["db"]->query( $sql );
            $row = $res->fetchRow();
            $rows["down"] = $row["anz"];
            $sql = "SELECT
                                        count(current_state) AS anz
                                FROM
                                        hoststatus
                                WHERE
                                        instance_id = " . $GLOBALS["cfg"]["instance"] . "
                                AND
                                        current_state = 2
                        ";
            $res = $GLOBALS["db"]->query( $sql );
            $row = $res->fetchRow();
            $rows["unreachable"] = $row["anz"];
            $rows["total"] = array_sum( $rows );
            return $rows;
        }
    }

?>