Project

General

Profile

Revision 0e0753c8

ID0e0753c8cfad3350b7b0215005ebb1bcf41cf7d6
Parent a5c9df40
Child b204adb9

Added by Romain Chollet over 7 years ago

Correction d'un bug d'affichage, ajout des faux tests logiciels

Dans glpi, une interruption avait lieu lors du déploiement de la
configuration vigilo. La cause de l'erreur était un reload de httpd
fait par vigilo. Cela a été résolu en faisant un script httpd dans
le dossier de configuration de vigilo.
L'ajout des faux logiciels nécessite encore des modifications qui
vont apparaître dans un prochain commit.

Change-Id: I434d4287526137b46387bf6377ceff7ddfd03de2

View differences:

Vigilo/VigiloHost.php
25 25

  
26 26
        $this->selectTemplates();
27 27
        $this->selectGroups();
28
        $this->monitorProcessor();
29 28
        $this->monitorMemory();
30 29
        $this->monitorNetworkInterfaces();
31 30
        $this->monitorSoftwares();
......
39 38

  
40 39
    protected function selectTemplates()
41 40
    {
42
        if ($this->computer->getField("template_name")) {
41
	$template_name = $this->computer->getField("template_name");
42

  
43
        if ($template_name && $template_name !== "N/A") {
43 44
            $this->children[] = new VigiloHostTemplate($this->computer->getField("template_name"));
44 45
        }
45 46
        $refs = array(
......
53 54
            $id = $this->computer->fields[$field];
54 55
            $value = Dropdown::getDropdownName($table, $id);
55 56
            if ($value !== "" && $value !== null && $value !== " "
56
                && $value !== false && $value !== "-----"
57
                && $value !== false && $value !== "-----" && $value !== 'N/A'
57 58
            ) {
58 59
                $model[] = $value;
59 60
            }
......
74 75
        $location->getFromDB($this->computer->fields["locations_id"]);
75 76
        if (!($location->getName()=='N/A')) {
76 77
            $locationCompleteName=explode(" > ", $location->getField("completename"));
77
            $locationRealName="/" . implode("/", $locationCompleteName);
78
            $locationRealName=implode("/", $locationCompleteName);
78 79
            $this->children[] = new VigiloGroup($locationRealName);
79 80
        }
80 81

  
......
82 83
        $entity->getFromDB($this->computer->fields["entities_id"]);
83 84
        if (!($entity->getName()=='N/A')) {
84 85
            $entityCompleteName=explode(" > ", $entity->getField("completename"));
85
            $entityRealName="/" . implode("/", $entityCompleteName);
86
            $entityRealName=implode("/", $entityCompleteName);
86 87
            $this->children[] = new VigiloGroup($entityRealName);
87 88
        }
88 89

  
......
122 123
        return $address;
123 124
    }
124 125

  
125
    protected function monitorProcessor()
126
    {
127
        $this->children[] = new VigiloTest('CPU');
128
    }
129

  
130 126
    protected function monitorMemory()
131 127
    {
132 128
        global $DB;
......
176 172
            }
177 173
            $args[] = new VigiloArg('label', $label);
178 174
            $args[] = new VigiloArg('ifname', $port->getName());
179
            ;
180 175
            $this->children[] = new VigiloTest('Interface', $args);
181 176

  
182 177
            // Retrieve all IP addresses associated with this interface.
Vigilo/VigiloHost.php~
1
<?php
2

  
3
class VigiloHost extends VigiloXml
4
{
5
    protected $computer;
6
    protected $addresses;
7
    protected $ventilation;
8
    protected $children;
9
    protected $agent;
10

  
11
    public function __construct($computer)
12
    {
13
        $this->agent        = null;
14
        $this->ventilation  = "Servers";
15
        $this->computer     = $computer;
16
        $this->addresses    = array();
17
        $this->children     = array();
18

  
19
        if (class_exists('PluginFusioninventoryAgent')) {
20
            $agent = new PluginFusioninventoryAgent();
21
            if ($agent->getAgentWithComputerid($this->computer->getID()) !== false)
22
                $this->agent = $agent;
23
        }
24

  
25
        $this->selectTemplates();
26
        $this->selectGroups();
27
        $this->monitorProcessor();
28
        $this->monitorMemory();
29
        $this->monitorNetworkInterfaces();
30
        $this->monitorSoftwares();
31
        $this->monitorPartitions();
32
    }
33

  
34
    public function getName()
35
    {
36
        return $this->computer->getName();
37
    }
38

  
39
    protected function selectTemplates()
40
    {
41
        $refs = array(
42
            "glpi_operatingsystems" => "operatingsystems_id",
43
            "glpi_operatingsystemversions" => "operatingsystemversions_id",
44
            "glpi_operatingsystemservicepacks" => "operatingsystemservicepacks_id",
45
        );
46

  
47
        $model = array();
48
        foreach ($refs as $table => $field) {
49
            $id = $this->computer->fields[$field];
50
            $value = Dropdown::getDropdownName($table, $id);
51
            if ($value !== "" && $value !== null && $value !== "&nbsp;" &&
52
                $value !== false && $value !== "-----") {
53
                $model[] = $value;
54
            }
55
        }
56

  
57
        if (!count($model))
58
            $model = "default";
59
        else
60
            $model = implode(" - ", $model);
61

  
62
        $this->children[] = new VigiloHostTemplate($model);
63
    }
64

  
65
    protected function selectGroups()
66
    {
67
        $location = new Location();
68
        $location->getFromDB($this->computer->fields["locations_id"]);
69
        $location = $location->getName();
70

  
71
        if (!$location)
72
            $location = "Servers";
73

  
74
        $this->children[] = new VigiloGroup($location);
75
    }
76

  
77
    protected function selectAddress()
78
    {
79
        static $address = null;
80

  
81
        if ($address === null && $this->agent) {
82
            $addresses = $this->agent->getIPs();
83
            if (count($addresses))
84
                $address = current($addresses);
85
        }
86

  
87
        if ($address === null) {
88
            $address = $this->$computer->getName();
89
            foreach ($this->addresses as $addr) {
90
                if (!$addr->is_ipv4())
91
                    continue;
92

  
93
                $textual = $addr->getTextual();
94
                if (is_string($textual)) {
95
                    $address = $textual;
96
                    break;
97
                }
98
            }
99
        }
100

  
101
        return $address;
102
    }
103

  
104
    protected function monitorProcessor()
105
    {
106
        $this->children[] = new VigiloTest('CPU');
107
    }
108

  
109
    protected function monitorMemory()
110
    {
111
        global $DB;
112

  
113
        $total = 0;
114
        $query = Item_DeviceMemory::getSQLRequestToSearchForItem(
115
            $this->computer->getType(),
116
            $this->computer->getID()
117
        );
118

  
119
        foreach ($DB->query($query) as $mem) {
120
            $memory = new Item_DeviceMemory();
121
            $memory->getFromDB($mem['id']);
122
            $total += $memory->fields['size'] * 1024 * 1024;
123
        }
124

  
125
        if ($total > 0)
126
            $this->children[] = new VigiloTest('RAM');
127
    }
128

  
129
    protected function monitorNetworkInterfaces()
130
    {
131
        global $DB;
132

  
133
        $query = NetworkPort::getSQLRequestToSearchForItem(
134
            $this->computer->getType(),
135
            $this->computer->getID()
136
        );
137

  
138
        foreach ($DB->query($query) as $np) {
139
            $query2 = NetworkName::getSQLRequestToSearchForItem("NetworkPort", $np['id']);
140

  
141
            $port = new NetworkPort();
142
            $port->getFromDB($np['id']);
143
            if ($port->getName() == 'lo')
144
                continue;
145

  
146
            $args   = array();
147
            $label  = isset($port->fields['comment']) ? $port->fields['comment'] : $port->getName();
148
            $args[] = new VigiloArg('label', $label);
149
            $args[] = new VigiloArg('name', $port->getName());
150
            // TODO: retrieve interface speed (from glpi_networkportethernets)
151
            $this->children[] = new VigiloTest('Interface', $args);
152

  
153
            // Retrieve all IP addresses associated with this interface.
154
            // This will be used later in selectAddress() to select
155
            // the most appropriate IP address to query this computer.
156
            foreach ($DB->query($query2) as $nn) {
157
                $query3 = IPAddress::getSQLRequestToSearchForItem("NetworkName", $nn['id']);
158
                foreach ($DB->query($query3) as $ip) {
159
                    $addr = new IPAddress();
160
                    if ($addr->getFromDB($ip['id']))
161
                        $this->addresses[] = $addr;
162
                }
163
            }
164
        }
165
    }
166

  
167
    protected function monitorSoftwares()
168
    {
169
        
170
    }
171

  
172
    protected function monitorPartitions()
173
    {
174
        global $DB;
175

  
176
        $query = ComputerDisk::getSQLRequestToSearchForItem(
177
            $this->computer->getType(),
178
            $this->computer->getID()
179
        );
180

  
181
        foreach ($DB->query($query) as $cd) {
182
            $disk = new ComputerDisk();
183
            $disk->getFromDB($cd['id']);
184

  
185
            $args = array();
186
            $args[] = new VigiloArg('label', $disk->getName());
187
            $args[] = new VigiloArg('partname', $disk->fields['mountpoint']);
188
            $total = $disk->fields['totalsize'];
189
            if (!empty($total))
190
                $args[] = new VigiloArg('max', $total * 1024 * 1024);
191
            $this->children[] = new VigiloTest('Partition', $args);
192
        }
193
    }
194

  
195
    public function __toString()
196
    {
197
        $outXML=new DOMdocument();
198
      	$outXML->preserveWhiteSpace=false;
199
     	$outXML->formatOutput=true;
200
     	$outXML->loadXML(self::sprintf(
201
            '<?xml version="1.0"?>' .
202
            '<host name="%s" address="%s" ventilation="%s">%s</host>',
203
            $this->computer->getName(),
204
            $this->selectAddress(),
205
            "Servers",
206
            $this->children
207
	    ));
208
	return $outXML->saveXML();	
209
	
210
    }
211
}
Vigilo/VigiloSoftwareList.php
15 15
           'elserv'      =>array("addHTTPTest",array()), //HTTP server that runs on Emacsen
16 16
           'thin'        =>array("addHTTPTest",array()), //Fast and very simple Ruby web server
17 17
           'webdis'      =>array("addHTTPTest",array()), //Web server providing an HTTP interface to Redis
18

  
19 18
           //'ntp'=>array("addNTPTest",array()), //Network Time Protocol deamon and utility programs
20 19

  
21 20
           'vigilo-connector-metro'     =>array("addVigiloConnectorTest",array("metro")), //Vigilo module receiving and stocking metrology data
Vigilo/VigiloTestSoftware.php
24 24

  
25 25
    public function addRelevantTestWith($softwareName)
26 26
    {
27
        $functionArray=$this->softwareBase[$softwareName];
27
	if (substr($softwareName, 0, 20) === "vigilo-test-process-") 
28
	{
29
	    $functionArray=array("addCustomTest", array($softwareName));
30
	}
31
	else 
32
	{
33
            $functionArray=$this->softwareBase[$softwareName];
34
	}
28 35
        $this->testTable[]=call_user_func_array(array($this,$functionArray[0]), $functionArray[1]);
29 36
    }
30 37

  
38
    protected function addCustomTest($softwareName)
39
    {
40
        return new VigiloTest(substr($softwareName, 20));	
41
    }
42

  
31 43
    protected function addNTPTest()
32 44
    {
33
        //TODO : set up arguments
34
        $args=array();
45
	$args=array();
35 46
        //$address=0;
36 47
        //$args[]=new VigiloArg('address',$address);
37 48
        $args[]=new VigiloArg('crit', 0);
......
41 52

  
42 53
    protected function addNTPqTest()
43 54
    {
44
        //TODO: set up arguments
45 55
        $args=array();
46
        $args[]=new VigiloArg('crit', 0);
47
        $args[]=new VigiloArg('warn', 0);
56
        $args[]=new VigiloArg('crit', 2000);
57
        $args[]=new VigiloArg('warn', 5000);
48 58
        return new VigiloTest('NTPq', $args);
49 59
    }
50 60

  
51
    protected function addNTPSyncTest()
61
    protected function addNTPSyncTest() // OK
52 62
    {
53 63
        return new VigiloTest('NTPSync');
54 64
    }
55 65

  
56
    protected function addHTTPTest()
66
    protected function addHTTPTest() // OK
57 67
    {
58 68
        return new VigiloTest('HTTP');
59 69
    }
......
61 71
    protected function addMemcachedTest($computer)
62 72
    {
63 73
        $args=array();
64
        $args[]=new VigiloArg('port', 11211);//TODO: set up arguments
74
        $args[]=new VigiloArg('port', 11211);
65 75
        return new VigiloTest('Memcached', $args);
66 76
    }
67 77

  
......
72 82

  
73 83
    protected function addPGSQLTest($computer)
74 84
    {
75
        //TODO: set up arguments
76
        //$args=array();
77
        //$args[]=new VigiloArg('database',NULL);
78
        //$args[]=new VigiloArg('port',NULL);
79
        //$args[]=new VigiloArg('user',NULL);
80
        //return new VigiloTest('PostgreSQLConnection',$args);
85
        $args=array();
86
        $args[]=new VigiloArg('database',"postgres");
87
        $args[]=new VigiloArg('port',5432);
88
        $args[]=new VigiloArg('user',"postgres");
89
        return new VigiloTest('PostgreSQLConnection',$args);
81 90
    }
82 91

  
83 92
    protected function addProxyTest()
84 93
    {
85
        //TODO: set up arguments
86
        //$args=array();
87
        /*$args[]=new VigiloArg('auth',NULL);
88
        $args[]=new VigiloArg('port',NULL);
89
        $args[]=new VigiloArg('url',NULL);*/
90
        //return new VigiloTest('Proxy',$args);
94
        $args=array();
95
        $args[]=new VigiloArg('auth',"False");
96
        $args[]=new VigiloArg('port',8080);
97
        $args[]=new VigiloArg('url',"http://www.google.fr");
98
        return new VigiloTest('Proxy',$args);
91 99
    }
92 100

  
93 101
    protected function addRRDcachedTest($computer)
94 102
    {
95
        //TODO: set up arguments
96
        //$path=
97
        //$args=array();
98
        //$args[]=new VigiloArg('crit',0);
99
        //$args[]=new VigiloArg('path',$path);
100
        //$args[]=new VigiloArg('warn',0);
101
        //return new VigiloTest('RRDcached',$args);
103
        $path="/var/lib/vigilo/connector-metro/rrdcached.sock";
104
        $args=array();
105
        $args[]=new VigiloArg('crit',0);
106
        $args[]=new VigiloArg('path',$path);
107
        $args[]=new VigiloArg('warn',0);
108
        return new VigiloTest('RRDcached',$args);
102 109
    }
103 110

  
104 111
    protected function addSSHTest()
......
115 122

  
116 123
    protected function addVigiloCorrelatorTest()
117 124
    {
118
        //TODO :set up arguments
119
        //$args=array();
120
        //$args[]=new VigiloArg('rules',NULL);
121
        //$args[]=new VigiloArg('servicename',NULL);
122
        //return new VigiloTest('VigiloCorrelator',$args);
125
        $args=array();
126
        //$args[]=new VigiloArg('rules','');
127
        $args[]=new VigiloArg('servicename','vigilo-correlator');
128
        return new VigiloTest('VigiloCorrelator',$args);
123 129
    }
124 130

  
125
    protected function TestService($computer)
131
    protected function TestService($computer, $service)
126 132
    {
127
        //TODO: set up arguments
128
        //$args=array();
129
        //$args[]=new VigiloArg('svcname',NULL);
130
        //return new VigiloTest('Service',$args);
133
        $args=array();
134
        $args[]=new VigiloArg('svcname',$service);
135
        return new VigiloTest('Service',$args);
131 136
    }
132 137

  
133 138
    public function __toString()
front/menu.php
7 7
                    "PluginVigiloMenu", "menu");
8 8

  
9 9
    $res = null;
10
    $pipes = array();
11

  
10 12
    if (!empty($_POST["deploy"])) {
11 13
        $fds = array(
12 14
            1 => array("pipe", "w"),
13 15
            2 => array("pipe", "w"),
14 16
        );
15
        $cmd = "/usr/bin/sudo -n /usr/bin/vigiconf deploy -f --debug 2>&1";
17
	$cmd = "/usr/bin/sudo -n /usr/bin/vigiconf deploy -f --debug";
16 18
        $res = proc_open($cmd, $fds, $pipes);
17 19
        if (!is_resource($res))
18
            $res = false;
20
	    $res = false;
19 21
    }
20

  
21 22
    PluginVigiloMenu::displayMenu($res, $pipes);
22 23
} else {
23 24
    Html::displayRightError();
hook.php
62 62

  
63 63
    public function update($computer)
64 64
    {
65
	global $PLUGIN_HOOKS;
65 66
        if (isset($computer->oldvalues["name"])) {
66 67
            $this->unmonitor($computer->oldvalues["name"]);
67 68
        }
inc/menu.class.php
64 64
                    echo "ERROR: command timed out!\n";
65 65
                    break;
66 66
                }
67

  
68 67
                if (count($exc)) {
69 68
                    echo "UNKNOWN ERROR\n";
70 69
                    break;
......
73 72
                foreach ($read as $stream){
74 73
                    echo htmlspecialchars(fread($stream, 1024), ENT_HTML5 | ENT_QUOTES, "utf-8");
75 74
                };
76
                //ob_flush();
75

  
77 76
                flush();
78 77
                if (feof($pipes[1])){
79 78
                  break;

Also available in: Unified diff