Project

General

Profile

Revision a5c9df40

IDa5c9df40fd2ca43717d25b3fc592780752731d04
Parent bef4271a
Child 0e0753c8

Added by Thibault Louet over 7 years ago

Génération auto de l'XML de l'équipement supervisé.

Rend l'ensemble du code comforme au standard PSR2.
Ajoute la création du fichier XML des groupes.
Ajoute les balises groupes correctement dans le fichier XML des hôtes.
Rempli correctement la balise template dans le fichier XML des hôtes.

Change-Id: Ie8ae52e4912e7f34deb5e8a85dfef0a698cae6c9
Reviewed-on: https://vigilo-dev.si.c-s.fr/review/2153
Reviewed-by: Francois POIROTTE <>
Tested-by: Francois POIROTTE <>

View differences:

Vigilo/VigiloHost.php
18 18

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

  
25 26
        $this->selectTemplates();
......
38 39

  
39 40
    protected function selectTemplates()
40 41
    {
42
        if ($this->computer->getField("template_name")) {
43
            $this->children[] = new VigiloHostTemplate($this->computer->getField("template_name"));
44
        }
41 45
        $refs = array(
42 46
            "glpi_operatingsystems" => "operatingsystems_id",
43 47
            "glpi_operatingsystemversions" => "operatingsystemversions_id",
......
48 52
        foreach ($refs as $table => $field) {
49 53
            $id = $this->computer->fields[$field];
50 54
            $value = Dropdown::getDropdownName($table, $id);
51
            if ($value !== "" && $value !== null && $value !== "&nbsp;" &&
52
                $value !== false && $value !== "-----") {
55
            if ($value !== "" && $value !== null && $value !== "&nbsp;"
56
                && $value !== false && $value !== "-----"
57
            ) {
53 58
                $model[] = $value;
54 59
            }
55 60
        }
56 61

  
57
        if (!count($model))
62
        if (!count($model)) {
58 63
            $model = "default";
59
        else
64
        } else {
60 65
            $model = implode(" - ", $model);
66
        }
61 67

  
62 68
        $this->children[] = new VigiloHostTemplate($model);
63 69
    }
......
66 72
    {
67 73
        $location = new Location();
68 74
        $location->getFromDB($this->computer->fields["locations_id"]);
69
        $location = $location->getName();
75
        if (!($location->getName()=='N/A')) {
76
            $locationCompleteName=explode(" > ", $location->getField("completename"));
77
            $locationRealName="/" . implode("/", $locationCompleteName);
78
            $this->children[] = new VigiloGroup($locationRealName);
79
        }
70 80

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

  
74
        $this->children[] = new VigiloGroup($location);
89
        $manufacturer = new Manufacturer();
90
        $manufacturer->getFromDB($this->computer->fields["manufacturers_id"]);
91
        if (!($manufacturer->getName()=='N/A')) {
92
            $this->children[] = new VigiloGroup($manufacturer->getName());
93
        }
75 94
    }
76 95

  
77 96
    protected function selectAddress()
......
80 99

  
81 100
        if ($address === null && $this->agent) {
82 101
            $addresses = $this->agent->getIPs();
83
            if (count($addresses))
102
            if (count($addresses)) {
84 103
                $address = current($addresses);
104
            }
85 105
        }
86 106

  
87 107
        if ($address === null) {
88 108
            $address = $this->computer->getName();
89 109
            foreach ($this->addresses as $addr) {
90
                if (!$addr->is_ipv4())
110
                if (!$addr->is_ipv4()) {
91 111
                    continue;
112
                }
92 113

  
93 114
                $textual = $addr->getTextual();
94 115
                if (is_string($textual)) {
......
122 143
            $total += $memory->fields['size'] * 1024 * 1024;
123 144
        }
124 145

  
125
        if ($total > 0)
146
        if ($total > 0) {
126 147
            $this->children[] = new VigiloTest('RAM');
148
        }
127 149
    }
128 150

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

  
133 154
        $query = NetworkPort::getSQLRequestToSearchForItem(
134 155
            $this->computer->getType(),
135 156
            $this->computer->getID()
......
137 158

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

  
141 161
            $port = new NetworkPort();
162
            $ethport = new NetworkPortEthernet();
142 163
            $port->getFromDB($np['id']);
143
            if ($port->getName() == 'lo')
164
            if ($port->getName() == 'lo') {
144 165
                continue;
166
            }
145 167

  
146 168
            $args   = array();
147 169
            $label  = isset($port->fields['comment']) ? $port->fields['comment'] : $port->getName();
170
            $ethport = $ethport->find('networkports_id=' . $np['id']);
171
            foreach ($ethport as $rowEthPort) {
172
                if ($rowEthPort['speed']) {
173
                    $args[] = new VigiloArg('max', $rowEthPort['speed']);
174
                    break;
175
                }
176
            }
148 177
            $args[] = new VigiloArg('label', $label);
149
            $args[] = new VigiloArg('name', $port->getName());
150
            // TODO: retrieve interface speed (from glpi_networkportethernets)
178
            $args[] = new VigiloArg('ifname', $port->getName());
179
            ;
151 180
            $this->children[] = new VigiloTest('Interface', $args);
152 181

  
153 182
            // Retrieve all IP addresses associated with this interface.
......
157 186
                $query3 = IPAddress::getSQLRequestToSearchForItem("NetworkName", $nn['id']);
158 187
                foreach ($DB->query($query3) as $ip) {
159 188
                    $addr = new IPAddress();
160
                    if ($addr->getFromDB($ip['id']))
189
                    if ($addr->getFromDB($ip['id'])) {
161 190
                        $this->addresses[] = $addr;
191
                    }
162 192
                }
163 193
            }
164 194
        }
......
166 196

  
167 197
    protected function monitorSoftwares()
168 198
    {
169
        
199
        global $DB;
200
        $listOfTest=new VigiloTestSoftware($this->computer);
201
        $computerSoftwareVersion=new Computer_SoftwareVersion();
202
        $ids=$computerSoftwareVersion->find('computers_id=' . $this->computer->getID());
203
        foreach ($ids as $id) {
204
            if ($id['softwareversions_id']) {
205
                $softwareVersion=new SoftwareVersion();
206
                $ids2=$softwareVersion->find('id=' . $id['softwareversions_id']);
207
                foreach ($ids2 as $id2) {
208
                    if ($id2['softwares_id']) {
209
                        $software=new Software();
210
                        $software->getFromDB($id2['softwares_id']);
211
                        $listOfTest->addRelevantTestWith($software->getName());
212
                    }
213
                }
214
            }
215
        }
216
        foreach ($listOfTest->getTable() as $test) {
217
             $this->children[]=$test;
218
        }
170 219
    }
171 220

  
172 221
    protected function monitorPartitions()
......
186 235
            $args[] = new VigiloArg('label', $disk->getName());
187 236
            $args[] = new VigiloArg('partname', $disk->fields['mountpoint']);
188 237
            $total = $disk->fields['totalsize'];
189
            if (!empty($total))
238
            if (!empty($total)) {
190 239
                $args[] = new VigiloArg('max', $total * 1024 * 1024);
240
            }
191 241
            $this->children[] = new VigiloTest('Partition', $args);
192 242
        }
193 243
    }
......
195 245
    public function __toString()
196 246
    {
197 247
        $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
	
248
        $outXML->preserveWhiteSpace=false;
249
        $outXML->formatOutput=true;
250
        $outXML->loadXML(
251
            self::sprintf(
252
                '<?xml version="1.0"?>' .
253
                '<host name="%s" address="%s" ventilation="%s">%s</host>',
254
                $this->computer->getName(),
255
                $this->selectAddress(),
256
                "Servers",
257
                $this->children
258
            )
259
        );
260
        return $outXML->saveXML();
210 261
    }
211
}
262
}

Also available in: Unified diff