Subversion-Projekte lars-tiefland.nagios-php

Revision

Revision 84 | Zur aktuellen Revision | 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: 85 $
8
     */
9
 
10
    // $Id: common.php 85 2013-01-02 13:25:47Z 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"];
26
    $opts = array(
27
        "persistent" => true,
28
        "portability" => MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL ^
29
            MDB2_PORTABILITY_FIX_CASE,
30
        );
31
    $dsn = array(
32
        "phptype" => "mysqli",
33
        "username" => $GLOBALS["cfg"]["db"]["user"],
34
        "password" => $GLOBALS["cfg"]["db"]["pass"],
35
        "hostspec" => $GLOBALS["cfg"]["db"]["server"],
36
        "database" => $GLOBALS["cfg"]["db"]["db"],
37
        "new_link" => true,
38
        );
39
    $GLOBALS["db"] = MDB2::connect( $dsn, $opts );
40
    if ( PEAR::isError( $GLOBALS["db"] ) )
41
    {
42
        trigger_error( "Keine Verbindung zur Datenbank möglich!\n", E_USER_ERROR );
43
    }
44
    $GLOBALS["db"]->setfetchMode( MDB2_FETCHMODE_ASSOC );
45
 
46
    $GLOBALS["ui"]->assign( "cfg", $GLOBALS["cfg"] );
47
    $nagiosVersion = getNagiosVersion();
48
    $programStatus = getProgramStatus();
49
    $runtimeInfo = getRuntimeInfo();
50
    $GLOBALS["ui"]->assign( "nagiosVersion", $nagiosVersion );
51
    $GLOBALS["ui"]->assign( "programStatus", $programStatus );
52
    $GLOBALS["ui"]->assign( "runtimeInfo", $runtimeInfo );
53
 
54
    function getNagiosVersion()
55
    {
56
        $sql = "SELECT
57
                program_version
58
            FROM
59
                processevents pe
60
            JOIN
61
                programstatus ps
62
            ON
63
                pe.event_time = ps.program_start_time
64
            WHERE
65
                pe.instance_id = " . $GLOBALS["cfg"]["instance"] . "
66
            AND
67
                pe.instance_id = ps.instance_id
68
            AND
69
                pe.process_id = ps.process_id
70
        ";
71
        $res = $GLOBALS["db"]->query( $sql );
72
        $row = $res->fetchRow();
73
        return $row["program_version"];
74
    }
75
 
76
    function getProgramStatus()
77
    {
78
        $sql = "SELECT
79
                *
80
            FROM
81
                programstatus ps
82
            WHERE
83
                ps.instance_id = " . $GLOBALS["cfg"]["instance"] . "
84
        ";
85
        $res = $GLOBALS["db"]->query( $sql );
86
        $info = $res->fetchAll();
87
        return $info;
88
    }
89
 
90
    function getRuntimeInfo()
91
    {
92
        $sql = "SELECT
93
                varname,
94
                varvalue
95
            FROM
96
                runtimevariables
97
            WHERE
98
                instance_id = " . $GLOBALS["cfg"]["instance"] . "
99
        ";
100
        $res = $GLOBALS["db"]->query( $sql );
101
        while ( $row = $res->fetchRow() )
102
        {
103
            $ret[$row["varname"]] = $row["varvalue"];
104
        }
105
        return $ret;
106
    }
107
 
108
?>