Subversion-Projekte lars-tiefland.nagios-php

Revision

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

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
9 lars 2
 
3
    class host
4
    {
42 lars 5
        public $display_name;
6
        public $host_id;
7
        public $host_object_id;
47 lars 8
        public $services;
42 lars 9
 
47 lars 10
        public function __construct( $id )
42 lars 11
        {
47 lars 12
            $sql = "SELECT
42 lars 13
                    host_id,
14
                    display_name,
15
                    host_object_id
16
                FROM
17
                    hosts
18
                WHERE
19
                    host_id = $id
20
                AND
21
                    instance_id = " . $GLOBALS["cfg"]["instance"] . "
22
            ";
47 lars 23
            $res = $GLOBALS["db"]->query( $sql );
44 lars 24
            $row = $res->fetchRow();
25
            //$this->host_id=$row["host_id"];
47 lars 26
            foreach ( $row as $feld => $wert )
44 lars 27
            {
45 lars 28
                $this->$feld = $wert;
44 lars 29
            }
47 lars 30
            $this->services = host::getHostServiceList( $id );
42 lars 31
        }
47 lars 32
 
33
        public static function getHostServiceList( $host_id )
34
        {
35
            $sql = "SELECT
36
                    service_id
37
                FROM
38
                    services
39
                WHERE
40
                    host_object_id = $host_id
41
                AND
42
                    instance_id = " . $GLOBALS["cfg"]["instance"] . "
43
            ";
44
            $res = $GLOBALS["db"]->query( $sql );
45
            while ( $row = $res->fetchRow() )
46
            {
47
                $ret[] = new service( $row["service_id"] );
48
            }
49
            return $ret;
50
        }
9 lars 51
        public static function getStatusList()
52
        {
53
            $sql = "SELECT
1 lars 54
					count(current_state) AS anz
55
				FROM
56
					hoststatus
57
				WHERE
58
					instance_id = " . $GLOBALS["cfg"]["instance"] . "
59
				AND
60
					current_state = 0
61
			";
9 lars 62
            $res = $GLOBALS["db"]->query( $sql );
63
            $row = $res->fetchRow();
64
            $rows["up"] = $row["anz"];
65
            $sql = "SELECT
1 lars 66
					count(current_state) AS anz
67
				FROM
68
					hoststatus
69
				WHERE
70
					instance_id = " . $GLOBALS["cfg"]["instance"] . "
71
				AND
72
					current_state = 1
73
			";
9 lars 74
            $res = $GLOBALS["db"]->query( $sql );
75
            $row = $res->fetchRow();
76
            $rows["down"] = $row["anz"];
77
            $sql = "SELECT
1 lars 78
					count(current_state) AS anz
79
				FROM
80
					hoststatus
81
				WHERE
82
					instance_id = " . $GLOBALS["cfg"]["instance"] . "
83
				AND
84
					current_state = 2
85
			";
9 lars 86
            $res = $GLOBALS["db"]->query( $sql );
87
            $row = $res->fetchRow();
88
            $rows["unreachable"] = $row["anz"];
89
            $rows["total"] = array_sum( $rows );
90
            return $rows;
91
        }
92
    }
93
 
1 lars 94
?>