Subversion-Projekte lars-tiefland.nagios-php

Revision

Revision 108 | 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: hostgroup.php 115 2013-01-05 19:05:29Z lars $

    /**
     * hostGroup
     * 
     * @package nagios-php
     * @author Lars Tiefland
     * @copyright 2013
     * @version $Id: hostgroup.php 115 2013-01-05 19:05:29Z lars $
     * @access public
     */
    class hostGroup
    {
        public $alias;
        public $hostgroup_id;
        public $members;
        /**
         * hostGroup::__construct()
         * 
         * @param mixed $id
         * @return
         */
        public function __construct( $id )
        {
            $sql = "SELECT
                    alias,
                    hostgroup_id
                FROM
                    hostgroups
                WHERE
                    instance_id = " . $GLOBALS["cfg"]["instance"] . "
                AND
                    hostgroup_id = $id
            ";
            $res = $GLOBALS["db"]->query( $sql );
            $row = $res->fetchRow();
            foreach ( $row as $feld => $wert )
            {
                $this->$feld = $wert;
            }
            $this->members = $this->getMemberList( $id );
        }

        /**
         * hostGroup::getList()
         * 
         * @return
         */
        public static function getList()
        {
            $sql="SELECT
                    hostgroup_id
                FROM
                    hostgroups
                WHERE
                    instance_id = " . $GLOBALS["cfg"]["instance"] . "
            ";
            $res = $GLOBALS["db"]->query( $sql );
            while ( $row = $res->fetchRow() )
            {
                $ret[] = new hostGroup( $row["hostgroup_id"] );
            }
            return $ret;
        }

        /**
         * hostGroup::getMemberList()
         * 
         * @param mixed $hg_id
         * @return
         */
        private function getMemberList( $hg_id )
        {
            $sql = "SELECT
                    host_object_id
                FROM
                    hostgroup_members
                WHERE
                    instance_id = " . $GLOBALS["cfg"]["instance"] . "
                AND
                    hostgroup_id = $hg_id
            ";
            $res = $GLOBALS["db"]->query( $sql );
            while ( $row = $res->fetchRow() )
            {
                $ret[] = new host( $row["host_object_id"], true );
            }
            return $ret;
        }
    }

?>