Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

glpi / src / Vigilo / VigiloTestSoftware.php @ 077e4de7

History | View | Annotate | Download (4.5 KB)

1
<?php
2

    
3
class VigiloTestSoftware
4
{
5
    protected $testTable;
6
    protected $softwareBase;
7
    protected $computer;
8
    protected $addedTests;
9

    
10
    public function __construct($computer)
11
    {
12
        $this->computer=$computer;
13
        $this->softwareBase = getSoftwareList($this->computer);
14
        $this->testTable=array();
15
        $this->addedTests=array();
16
    }
17

    
18
    public function getTable()
19
    {
20
        return $this->testTable;
21
    }
22

    
23
    public function addRelevantTestWith($softwareName)
24
    {
25
        if (strstr($softwareName, "vigilo-test")) {
26
            $functionArray = array("addCustomTest", array($softwareName));
27
        } else {
28
            if (!array_key_exists($softwareName, $this->softwareBase)) {
29
                return;
30
            }
31
            $functionArray = $this->softwareBase[$softwareName];
32
        }
33
        $this->testTable[] = call_user_func_array(array($this, $functionArray[0]), $functionArray[1]);
34
    }
35

    
36
    protected function addCustomTest($softwareName)
37
    {
38
        $software_name = str_replace('vigilo-test-', '', $softwareName);
39
        $explode_software_name = explode('-', $software_name, 2);
40
        $args = array();
41

    
42
        switch (strtolower($explode_software_name[0])) {
43
            case "process":
44
                $args[] = new VigiloArg('processname', $explode_software_name[1]);
45
                $explode_software_name[0] = "Process";
46
                break;
47

    
48
            case "service":
49
                $args[] = new VigiloArg('svcname', $explode_software_name[1]);
50
                $explode_software_name[0] = "Service";
51
                break;
52

    
53
            case "tcp":
54
                $args[] = new VigiloArg('port', $explode_software_name[1]);
55
                $explode_software_name[0] = "TCP";
56
                break;
57

    
58
            default:
59
                return;
60
        }
61

    
62
        return new VigiloTest($explode_software_name[0], $args);
63
    }
64

    
65
    protected function addNTPTest()
66
    {
67
        $args = array();
68
        //$address=0;
69
        //$args[] = new VigiloArg('address', $address);
70
        $args[] = new VigiloArg('crit', 0);
71
        $args[] = new VigiloArg('warn', 0);
72
        return new VigiloTest('NTP', $args);
73
    }
74

    
75
    protected function addNTPqTest()
76
    {
77
        $args=array();
78
        $args[] = new VigiloArg('crit', 2000);
79
        $args[] = new VigiloArg('warn', 5000);
80
        return new VigiloTest('NTPq', $args);
81
    }
82

    
83
    protected function addNTPSyncTest() // OK
84
    {
85
        return new VigiloTest('NTPSync');
86
    }
87

    
88
    protected function addHTTPTest() // OK
89
    {
90
        return new VigiloTest('HTTP');
91
    }
92

    
93
    protected function addMemcachedTest($computer)
94
    {
95
        $args=array();
96
        $args[] = new VigiloArg('port', 11211);
97
        return new VigiloTest('Memcached', $args);
98
    }
99

    
100
    protected function addNagiosTest()
101
    {
102
        return new VigiloTest('Nagios');
103
    }
104

    
105
    protected function addPGSQLTest($computer)
106
    {
107
        $args=array();
108
        $args[] = new VigiloArg('database', "postgres");
109
        $args[] = new VigiloArg('port', 5432);
110
        $args[] = new VigiloArg('user', "postgres");
111
        return new VigiloTest('PostgreSQLConnection', $args);
112
    }
113

    
114
    protected function addProxyTest()
115
    {
116
        $args=array();
117
        $args[] = new VigiloArg('auth', "False");
118
        $args[] = new VigiloArg('port', 8080);
119
        $args[] = new VigiloArg('url', "http://www.google.fr");
120
        return new VigiloTest('Proxy', $args);
121
    }
122

    
123
    protected function addRRDcachedTest($computer)
124
    {
125
        $path="/var/lib/vigilo/connector-metro/rrdcached.sock";
126
        $args=array();
127
        $args[] = new VigiloArg('crit', 0);
128
        $args[] = new VigiloArg('path', $path);
129
        $args[] = new VigiloArg('warn', 0);
130
        return new VigiloTest('RRDcached', $args);
131
    }
132

    
133
    protected function addSSHTest()
134
    {
135
        return new VigiloTest('SSH');
136
    }
137

    
138
    protected function addVigiloConnectorTest($type)
139
    {
140
        $args=array();
141
        $args[] = new VigiloArg('type', $type);
142
        return new VigiloTest('VigiloConnector', $args);
143
    }
144

    
145
    protected function addVigiloCorrelatorTest()
146
    {
147
        $args=array();
148
        //$args[] = new VigiloArg('rules', '');
149
        $args[] = new VigiloArg('servicename', 'vigilo-correlator');
150
        return new VigiloTest('VigiloCorrelator', $args);
151
    }
152

    
153
    protected function addTestService($computer, $service)
154
    {
155
        $args=array();
156
        $args[] = new VigiloArg('svcname', $service);
157
        return new VigiloTest('Service', $args);
158
    }
159

    
160
    public function __toString()
161
    {
162
        return $this->child;
163
    }
164
}