Subversion-Projekte lars-tiefland.nagios-php

Revision

Revision 84 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
9 lars 2
 
82 lars 3
    /**
86 lars 4
     * @package nagios-php
5
     * @author Lars Tiefland <ltiefland@gmail.com>
6
     * @copyright 2013
7
     * @version $Rev: 86 $
8
     */
9
 
10
    // $Id: host.php 86 2013-01-02 13:28:36Z lars $
11
 
12
    /**
82 lars 13
     * host
14
     *
15
     * @package nagios-php
16
     * @author Lars Tiefland
17
     * @copyright 2012
18
     * @version $Rev: 86 $
19
     * @access public
20
     */
9 lars 21
    class host
22
    {
42 lars 23
        public $display_name;
24
        public $host_id;
25
        public $host_object_id;
47 lars 26
        public $services;
42 lars 27
 
82 lars 28
        /**
29
         * host::__construct()
30
         *
31
         * @param mixed $id
32
         * @return
33
         */
47 lars 34
        public function __construct( $id )
42 lars 35
        {
47 lars 36
            $sql = "SELECT
42 lars 37
                    host_id,
38
                    display_name,
39
                    host_object_id
40
                FROM
41
                    hosts
42
                WHERE
43
                    host_id = $id
44
                AND
45
                    instance_id = " . $GLOBALS["cfg"]["instance"] . "
46
            ";
47 lars 47
            $res = $GLOBALS["db"]->query( $sql );
44 lars 48
            $row = $res->fetchRow();
49
            //$this->host_id=$row["host_id"];
47 lars 50
            foreach ( $row as $feld => $wert )
44 lars 51
            {
45 lars 52
                $this->$feld = $wert;
44 lars 53
            }
47 lars 54
            $this->services = host::getHostServiceList( $id );
42 lars 55
        }
47 lars 56
 
82 lars 57
        /**
58
         * host::getHostServiceList()
59
         *
60
         * @param mixed $host_id
61
         * @return
62
         */
47 lars 63
        public static function getHostServiceList( $host_id )
64
        {
65
            $sql = "SELECT
66
                    service_id
67
                FROM
68
                    services
69
                WHERE
70
                    host_object_id = $host_id
71
                AND
72
                    instance_id = " . $GLOBALS["cfg"]["instance"] . "
73
            ";
74
            $res = $GLOBALS["db"]->query( $sql );
75
            while ( $row = $res->fetchRow() )
76
            {
77
                $ret[] = new service( $row["service_id"] );
78
            }
79
            return $ret;
80
        }
82 lars 81
        /**
82
         * host::getStatusList()
83
         *
84
         * @return
85
         */
9 lars 86
        public static function getStatusList()
87
        {
88
            $sql = "SELECT
1 lars 89
					count(current_state) AS anz
90
				FROM
91
					hoststatus
92
				WHERE
93
					instance_id = " . $GLOBALS["cfg"]["instance"] . "
94
				AND
95
					current_state = 0
96
			";
9 lars 97
            $res = $GLOBALS["db"]->query( $sql );
98
            $row = $res->fetchRow();
99
            $rows["up"] = $row["anz"];
100
            $sql = "SELECT
1 lars 101
					count(current_state) AS anz
102
				FROM
103
					hoststatus
104
				WHERE
105
					instance_id = " . $GLOBALS["cfg"]["instance"] . "
106
				AND
107
					current_state = 1
108
			";
9 lars 109
            $res = $GLOBALS["db"]->query( $sql );
110
            $row = $res->fetchRow();
111
            $rows["down"] = $row["anz"];
112
            $sql = "SELECT
1 lars 113
					count(current_state) AS anz
114
				FROM
115
					hoststatus
116
				WHERE
117
					instance_id = " . $GLOBALS["cfg"]["instance"] . "
118
				AND
119
					current_state = 2
120
			";
9 lars 121
            $res = $GLOBALS["db"]->query( $sql );
122
            $row = $res->fetchRow();
123
            $rows["unreachable"] = $row["anz"];
124
            $rows["total"] = array_sum( $rows );
125
            return $rows;
126
        }
127
    }
128
 
1 lars 129
?>