Subversion-Projekte lars-tiefland.nagios-php

Revision

Revision 85 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
85 lars 1
<?php
2
 
3
    /**
4
     * @package nagios-php
5
     * @author Lars Tiefland <ltiefland@gmail.com>
6
     * @copyright 2013
7
     * @version $Rev: 87 $
8
     */
9
 
10
    // $Id: common.php 87 2013-01-02 13:33:45Z lars $
11
 
12
    require_once "Config.php";
13
    require_once "MDB2.php";
14
    require_once "smarty/libs/Smarty.class.php";
15
    require_once "classes/host.php";
16
    require_once "classes/service.php";
17
    require_once "classes/hostgroup.php";
18
    require_once "classes/servicegroup.php";
19
    require_once "classes/contact.php";
20
 
21
    $GLOBALS["ui"] = new Smarty();
22
    $cfg = new Config();
23
    $cfg = $cfg->parseConfig( "config.xml", "xml" );
24
    $cfg = $cfg->toArray();
25
    $GLOBALS["cfg"] = $cfg["root"]["config"];
87 lars 26
    $GLOBALS["cfg"]["refreshIntervallJs"] = $GLOBALS["cfg"]["refreshIntervall"] *
27
        1000;
85 lars 28
    $opts = array(
29
        "persistent" => true,
30
        "portability" => MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL ^
31
            MDB2_PORTABILITY_FIX_CASE,
32
        );
33
    $dsn = array(
34
        "phptype" => "mysqli",
35
        "username" => $GLOBALS["cfg"]["db"]["user"],
36
        "password" => $GLOBALS["cfg"]["db"]["pass"],
37
        "hostspec" => $GLOBALS["cfg"]["db"]["server"],
38
        "database" => $GLOBALS["cfg"]["db"]["db"],
39
        "new_link" => true,
40
        );
41
    $GLOBALS["db"] = MDB2::connect( $dsn, $opts );
42
    if ( PEAR::isError( $GLOBALS["db"] ) )
43
    {
44
        trigger_error( "Keine Verbindung zur Datenbank möglich!\n", E_USER_ERROR );
45
    }
46
    $GLOBALS["db"]->setfetchMode( MDB2_FETCHMODE_ASSOC );
47
 
48
    $GLOBALS["ui"]->assign( "cfg", $GLOBALS["cfg"] );
49
    $nagiosVersion = getNagiosVersion();
50
    $programStatus = getProgramStatus();
51
    $runtimeInfo = getRuntimeInfo();
52
    $GLOBALS["ui"]->assign( "nagiosVersion", $nagiosVersion );
53
    $GLOBALS["ui"]->assign( "programStatus", $programStatus );
54
    $GLOBALS["ui"]->assign( "runtimeInfo", $runtimeInfo );
55
 
56
    function getNagiosVersion()
57
    {
58
        $sql = "SELECT
59
                program_version
60
            FROM
61
                processevents pe
62
            JOIN
63
                programstatus ps
64
            ON
65
                pe.event_time = ps.program_start_time
66
            WHERE
67
                pe.instance_id = " . $GLOBALS["cfg"]["instance"] . "
68
            AND
69
                pe.instance_id = ps.instance_id
70
            AND
71
                pe.process_id = ps.process_id
72
        ";
73
        $res = $GLOBALS["db"]->query( $sql );
74
        $row = $res->fetchRow();
75
        return $row["program_version"];
76
    }
77
 
78
    function getProgramStatus()
79
    {
80
        $sql = "SELECT
81
                *
82
            FROM
83
                programstatus ps
84
            WHERE
85
                ps.instance_id = " . $GLOBALS["cfg"]["instance"] . "
86
        ";
87
        $res = $GLOBALS["db"]->query( $sql );
88
        $info = $res->fetchAll();
89
        return $info;
90
    }
91
 
92
    function getRuntimeInfo()
93
    {
94
        $sql = "SELECT
95
                varname,
96
                varvalue
97
            FROM
98
                runtimevariables
99
            WHERE
100
                instance_id = " . $GLOBALS["cfg"]["instance"] . "
101
        ";
102
        $res = $GLOBALS["db"]->query( $sql );
103
        while ( $row = $res->fetchRow() )
104
        {
105
            $ret[$row["varname"]] = $row["varvalue"];
106
        }
107
        return $ret;
108
    }
109
 
110
?>