Subversion-Projekte lars-tiefland.nagios-php

Revision

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

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