Subversion-Projekte lars-tiefland.nagios-php

Revision

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