Subversion-Projekte lars-tiefland.nagios-php

Revision

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