Subversion-Projekte lars-tiefland.nagios-php

Revision

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