PDA

View Full Version : [Pb Inventaire] Pas d'infos ou infos pas bonne....


Esteban135
04-18-2005, 03:10 PM
Bonjour a tous.

Je me presente Esteban, j'ai débuté il y a peut de temps sous Oreon.

Et je me suis appercut avec ma MDK 10 qu'il y avais des qq tout petit soucis. surtout au niveaux info Snmp.

Si j'allais dans l'inventaire pour avoir des infos snmp de mes hosts cela marchaient pour une partie des infos:

-Nom
-Location
-Contact

pour le reste rien ?????

Alors je me suis un peut penché dessus...

Et j'ai trouvé et modifié le fichier profile_host.php

je m'explique j'ai mon snmp qui fonctionne tres bien. j'effectue en ligne de commande qq requettes snmp et la tout marche bien.

Voila pq je me suis penché sur le code.

Ex: pour le calcule des partitions en Go il faut faire un peut de mat.
La fonction dévelopé par les bon ti gas d'Oreon marche tres bien, mais comment choper l'info en snmp c pas trop cela..

ex pour récuperer l'info block qui permet de calculer la taille des disques la commande est :

snmpget -v 1 xxx.xxx.xxx.xxx -O v -c public .1.3.6.1.2.1.25.2.3.1.4.(num disque)

le resultat sort correctement : 4016 blocks

hors dans le fichier profile_host.php il est specifié d'efectuer un cut -d ' ' -f 2.

ce qui donne comme resultat: blocks hors l'info qui est bonne a avoir est : 4016
:lol:

j'ai donc revus le fichier pour que cela fonctionne avec mes MDK 10 et 10.1

j'ai fais de meme pour les ip et le reste.
Dites moi si cela fonctionne chez vous?

Merci d'avance.

Si join le code complet modifié :

--------- Profile_host.php -----------------------------------------------------

<?

/**

Oreon is developped with Apache Licence 2.0 :

http://www.apache.org/licenses/LICENSE-2.0.txt

Developped by : Jean Baptiste Gouret - Julien Mathis - Mathieu Mettre - Romain Le Merlus - Yohann Lecarpentier

Under control of Flavien Astraud, Jerome Landrieu for Epitech.

Oreon is developped in partnership with Linagora company.



For information : contact@oreon.org

*/

if (!isset($oreon))

exit();



$hosts = & $oreon->hosts;

if (!isset($oreon->profileHosts))

$oreon->loadProfileHosts();



if (isset($_GET["host_host_id"])) {

$host_id = $_GET["host_host_id"];

$update = false;

if (isset($_GET["update"]))

$update = true;

else {

if (!isset($oreon->profileHosts[$host_id]))

$update = true;

else

$ph = $oreon->profileHosts[$host_id];

}

if ($update) {

$ph = new ProfileHost($host_id);

$ph->set_contact(exec($oreon->optGen->get_snmp_path()."/snmpget -v 1 ".$hosts[$host_id]->get_address()." -O v -c ".$oreon->optGen->get_snmp_community()." .1.3.6.1.2.1.1.4.0 | cut -d ':' -f 2 "));

$ph->set_location(exec($oreon->optGen->get_snmp_path()."/snmpget -v 1 ".$hosts[$host_id]->get_address()." -O v -c ".$oreon->optGen->get_snmp_community()." .1.3.6.1.2.1.1.6.0 | cut -d ':' -f 2 "));

$os = exec($oreon->optGen->get_snmp_path()."/snmpget -v 1 ".$hosts[$host_id]->get_address()." -O v -c ".$oreon->optGen->get_snmp_community()." .1.3.6.1.2.1.1.1.0");

if (preg_match("/STRING:\s[a-zA-Z0-9]+\s/", $os, $regs))

$os_ = split(' ', $regs[0]);

if (isset($os_))

$ph->set_os($os_[1]);

else

$ph->set_os(NULL);

$ph->set_uptime(exec($oreon->optGen->get_snmp_path()."/snmpget -v 1 ".$hosts[$host_id]->get_address()." -O v -c ".$oreon->optGen->get_snmp_community()." .1.3.6.1.2.1.1.3.0 | cut -d ')' -f 2 | cut -d '.' -f 1"));

// Renvois le nombre d'interface reseaux du serveur interrogé.

$nb_interface = exec($oreon->optGen->get_snmp_path()."/snmpget -v 2c ".$hosts[$host_id]->get_address()." -O v -c ".$oreon->optGen->get_snmp_community()." .1.3.6.1.2.1.2.1.0 | cut -d ':' -f 2");

// renvois les numero d'index des interfaces

exec ($oreon->optGen->get_snmp_path()."/snmpwalk -v 2c ".$hosts[$host_id]->get_address()." -c ".$oreon->optGen->get_snmp_community()." .1.3.6.1.2.1.4.20.1.2 | cut -d ' ' -f 2 ", $index);

// Erreur de recuperation de l'index des Eth

//exec ($oreon->optGen->get_snmp_path()."/snmpwalk -v 2c ".$hosts[$host_id]->get_address()." -c ".$oreon->optGen->get_snmp_community()." .1.3.6.1.2.1.4.20.1.2 | cut -d ' ' -f 4 ", $index);

// renvois l'interfaces complet de Eth

exec ($oreon->optGen->get_snmp_path()."/snmpwalk -v 2c ".$hosts[$host_id]->get_address()." -c ".$oreon->optGen->get_snmp_community()." .1.3.6.1.2.1.4.20.1.2 ", $interfaces);

// renvois dans un tableau les adresse Ip des Eth

exec ($oreon->optGen->get_snmp_path()."/snmpwalk -v 2c ".$hosts[$host_id]->get_address()." -c ".$oreon->optGen->get_snmp_community()." .1.3.6.1.2.1.4.20.1.2 | cut -d '.' -f 2,3,4,5 | cut -d ' ' -f 1", $interfaces_IP);

$inter = $interfaces_IP;

// compte le nombre Interface Ethernet de la machine

$len = count ($interfaces);



for ($k = 0; $k < $len; $k++)

{

$test = $k;

$ni["pi_id"] = $k;

$ni["host_host_id"] = $host_id;

// Nom de l'interface

$modele = exec ($oreon->optGen->get_snmp_path()."/snmpget -v 1 ".$hosts[$host_id]->get_address()." -O v -c ".$oreon->optGen->get_snmp_community()." .1.3.6.1.2.1.2.2.1.2.$index[$k] | cut -d ':' -f 2 ");



$ni["pi_model"] = $modele;

$j = $k ;

// calcule de l'ip de la machine

/**

for ($l = 0; $l < $nb_interface; $l++) {

$temp = split(" ", "$interfaces[$l]");

//recuperation d'une varible temp dans toto

$toto = $interfaces[$l];

if (!strcmp("$interfaces[$j]", "$temp[3]")) {

$iphost = split ("\.", "$temp[0]");

$ip_tmp = "$iphost[1].$iphost[2].$iphost[3].$iphost[4]";

$ni["pi_ip"] = $ip_tmp;

break;

}

} */

$ni["pi_ip"] = $interfaces_IP[$k];

$speed = exec ($oreon->optGen->get_snmp_path()."/snmpget -v 1 ".$hosts[$host_id]->get_address()." -O v -c ".$oreon->optGen->get_snmp_community()." .1.3.6.1.2.1.2.2.1.5.1");

// $index[$k] | cut -d ' ' -f 2 ");

$speed = $speed / 100000;

$ni["pi_speed"] = $speed;

$mac = exec ($oreon->optGen->get_snmp_path()."/snmpget -v 1 ".$hosts[$host_id]->get_address()." -O v -c ".$oreon->optGen->get_snmp_community()." .1.3.6.1.2.1.2.2.1.6.$index[$k] | cut -d ' ' -f 2");

$ni["pi_mac"] = $mac;

$ph->netInterfaces[$k] = new NetInterface($ni);

//$ph->netInterface[$k]->set_status(exec($oreon->optGen->get_snmp_path()."/snmpget -v 1 ".$hosts[$host_id]->get_address()." -O v -c ".$oreon->optGen->get_snmp_community()." .1.3.6.1.2.1.2.2.1.7.$index[$k] | cut -d ':' -f 2"));

}

$ph->set_ram(exec($oreon->optGen->get_snmp_path()."/snmpget -v 1 ".$hosts[$host_id]->get_address()." -O v -c ".$oreon->optGen->get_snmp_community()." .1.3.6.1.2.1.25.2.2.0"));

$nb = exec ($oreon->optGen->get_snmp_path()."/snmpwalk -v 1 ".$hosts[$host_id]->get_address()." -O v -c ".$oreon->optGen->get_snmp_community()." .1.3.6.1.2.1.25.2.3.1.1 | wc -l");

$j = 1;

while ($j < $nb) {

$dk["pdisk_id"] = -1;

$dk["host_host_id"] = $host_id;

$part[$j] = exec($oreon->optGen->get_snmp_path()."/snmpget -v 1 ".$hosts[$host_id]->get_address()." -O v -c ".$oreon->optGen->get_snmp_community()." .1.3.6.1.2.1.25.2.3.1.3.$j");

$block[$j] = exec($oreon->optGen->get_snmp_path()."/snmpget -v 1 ".$hosts[$host_id]->get_address()." -O v -c ".$oreon->optGen->get_snmp_community()." .1.3.6.1.2.1.25.2.3.1.4.$j | cut -d ' ' -f 1");

$size[$j] = exec($oreon->optGen->get_snmp_path()."/snmpget -v 1 ".$hosts[$host_id]->get_address()." -O v -c ".$oreon->optGen->get_snmp_community()." .1.3.6.1.2.1.25.2.3.1.5.$j");

$space_used[$j] = exec($oreon->optGen->get_snmp_path()."/snmpget -v 1 ".$hosts[$host_id]->get_address()." -O v -c ".$oreon->optGen->get_snmp_community()." .1.3.6.1.2.1.25.2.3.1.6.$j | cut -d ' ' -f 2");

$size[$j] = round ($size[$j] * $block[$j] / 1000000000, 2);

$space_used[$j] = round ($space_used[$j] * $block[$j] / 1000000000, 2);

$partition = $part[$j];

// save new information about disk in DB

$space_free = $size[$j] - $space_used[$j];

if ($len >= 1) {

$len = strlen ($partition) - 1;

if ($partition[$len] == '\\')

$partition = $partition."\\";

}

$dk["pdisk_name"] = $partition;

$dk["pdisk_space"] = $size[$j];

$dk["pdisk_used_space"] = $space_used[$j];

$dk["pdisk_free_space"] = $space_free;

$ph->disks[$j-1] = new Disk($dk);

$j++;

}



exec($oreon->optGen->get_snmp_path()."/snmpwalk -v 1 ".$hosts[$host_id]->get_address()." -O v -c ".$oreon->optGen->get_snmp_community()." .1.3.6.1.2.1.25.6.3.1.2 | grep '\"' | cut -d ':' -f 2 ", $soft);

if (isset($soft)) {

if (is_file("./include/profileHost/".$host_id.".php"))

unlink("./include/profileHost/".$host_id.".php");

$filename = "./include/profileHost/".$host_id.".php";

if (!$handle = fopen($filename, 'w')) {

echo $lang['db_cannot_open'] . $filename;

exit;

}

$soft_names = NULL;

for ($s = 0; isset ($soft[$s]); $s++)

if (strcmp($soft[$s], ""))

if (!stristr($soft[$s], "Windows ") && (!stristr($soft[$s], " - KB"))) {

$soft_tab = split ("\"", $soft[$s]);

$ph->softwares[$s] = $soft_tab[1];

$soft_names .= $soft_tab[1]."|";

}

if ($soft_names)

sort($ph->softwares);

fwrite($handle, $soft_names);

fclose($handle);

}

$soft = NULL;

exec($oreon->optGen->get_snmp_path()."/snmpwalk -v 1 ".$hosts[$host_id]->get_address()." -O v -c ".$oreon->optGen->get_snmp_community()." .1.3.6.1.2.1.25.6.3.1.2 | grep '\"' | cut -d ':' -f 2 | grep ' - KB' ", $soft);

if (isset($soft)) {

$filename = "./include/profileHost/".$host_id."-UP.php";

if (!$handle = fopen($filename, 'w')) {

echo $lang['db_cannot_open'] . $filename;

exit;

}

$soft_names = NULL;

for ($s = 0; isset ($soft[$s]); $s++) {

if (strcmp($soft[$s], ""))

if (stristr($soft[$s], "Correctif") && (stristr($soft[$s], "KB"))) {

$soft_tab = split ("\"", $soft[$s]);

$ph->softwaresUP[$s] = $soft_tab[1];

$soft_names .= $soft_tab[1]."|";

}

}

if ($soft_names)

sort($ph->softwaresUP);

fwrite($handle, $soft_names);

fclose($handle);

}

$ph->set_update(time());

$oreon->saveProfileHost($ph);

}

}



?>



<td width="85%" valign="top" align="center">

<table width="60%" align="center" border="0" cellspacing="0" cellpadding="0">

<tr>

<td>



<? include ("tab3Top.php"); ?>

<table width="80%" align="center" cellspacing="0" cellpadding="0" border="0">

<tr>

<td valign="top" align="center" style="padding-top: 15px;">

<form method="get" action="">

<table>

<tr>

<td><? echo $lang['profile_h_list_host']; ?></td>

<td>

<select name="host_host_id" size="1">

<?

if (isset($hosts))

foreach($hosts as $host)

if ($host->get_register()) {

echo "<option value=".$host->get_id();

if (isset($_GET["host_host_id"]) && $_GET["host_host_id"] == $host->get_id())

echo " selected";

echo ">".$host->get_name()."</option>";

}

?>

</select>

</td>

</tr>

<tr>

<td><? echo $lang['profile_o_live_update']; ?></td>

<td><input type="checkbox" name="update"></td>

</tr>

<tr>

<td colspan="2"><input type="submit" value="OK"></td>

</tr>

</table>

<input type="hidden" name="p" value="<? echo $_GET["p"]; ?>">

</form>

</td>

</tr>

</table>

<? include ("tab3Bot.php"); ?>

<? if (isset($host_id)) { ?>

<table width="100%" align="center" border="0" cellspacing="0" cellpadding="3" style="padding-top: 20px;">

<tr>

<td>

<? include ("tab3Top.php"); ?>

<table align="center" width="90%" border="0" cellpadding="3" cellspacing="3">

<tr>

<td style="white-space: nowrap;"><? echo $lang['profile_h_name']; ?> : </td>

<td class="text10b"><? echo stripslashes($hosts[$host_id]->get_name()); ?></td>

</tr>

<tr>

<td style="white-space: nowrap;"><? echo $lang['profile_h_location']; ?> : </td>

<td class="text10b"><? echo stripslashes($ph->get_location()); ?> </td>

</tr>

<tr>

<td style="white-space: nowrap;"><? echo $lang['profile_h_contact']; ?> : </td>

<td class="text10b"><? echo stripslashes($ph->get_contact()); ?> </td>

</tr>

<tr>

<td style="white-space: nowrap;" valign="top"><? echo $lang['profile_h_os']; ?> : </td>

<td class="text10b"><? echo stripslashes($ph->get_os()); ?></td>

</tr>

<tr>

<td style="white-space: nowrap;"><? echo $lang['profile_h_uptime']; ?> : </td>

<td class="text10b"><? echo stripslashes($ph->get_uptime()); ?> </td>

</tr>

<? if (isset($ph->netInterfaces)) { ?>

<tr>

<td valign='top' style="white-space: nowrap;"><? echo $lang['profile_h_interface']; ?> : </td>

<td class="text10b">

<? foreach ($ph->netInterfaces as $netInterface) { ?>

<table width='100%' border='0' align='center' cellpadding='2' cellspacing='2'>

<tr>

<td colspan='4' class="text10b" bgcolor="#CCCCCC"><? echo stripslashes($netInterface->get_model()); ?></td>

</tr>

<tr>

<td width='12%'><? echo $lang['profile_h_ip']; ?></td>

<td width='30%' class="text10b"><? echo $netInterface->get_ip(); ?></td>

<td width='16%'><? echo $lang['profile_h_speed']; ?></td>

<td width='20%' class="text10b"><? echo $netInterface->get_speed(); ?> Mbps</td>

</tr>

<tr>

<td><? echo $lang['profile_h_mac']; ?></td>

<td colspan="3" class="text10b"><? echo stripslashes($netInterface->get_mac()); ?></td>

</tr>

</table>

<? } ?>

</td>

</tr>

<? } ?>

<tr>

<td style="white-space: nowrap;"><? echo $lang['profile_h_ram']; ?> : </td>

<td class="text10b"><? echo $ph->get_ram();?> </td>

</tr>

<? if (isset($ph->disks)) { ?>

<tr>

<td valign='top' style="white-space: nowrap;"><? echo $lang['profile_h_disk']; ?> : </td>

<td class="text10b">

<table width='100%' border='1' bordercolor="#CCCCCC" align='center' cellpadding='1' cellspacing='0'>

<tr bgcolor='#CCCCCC'>

<td valign='middle' align="center" class="text10b" style="padding: 8px; white-space: nowrap;">Partition</td>

<td valign='middle' align="center" class="text10b" style="padding: 8px; white-space: nowrap;">Size</td>

<td valign='middle' align="center" class="text10b" style="padding: 8px; white-space: nowrap;">Used space</td>

<td valign='middle' align="center" class="text10b" style="padding: 8px; white-space: nowrap;">Free space</td>

</tr>

<? foreach ($ph->disks as $disk) { ?>

<tr>

<td valign='top' align='center' class="text10b" style="white-space: nowrap;"><? echo $disk->get_name();?></td>

<td valign='top' align='center' class="text10b" style="white-space: nowrap;"><? echo $disk->get_space();?> Go</td>

<td valign='top' align='center' class="text10b" style="white-space: nowrap;"><? echo $disk->get_used_space();?> Go</td>

<td valign='top' align='center' class="text10b" style="white-space: nowrap;"><? echo $disk->get_free_space();?> Go</td>

</tr>

<? } ?>

</table>

</td>

</tr>

<? } ?>

<tr>

<td valign="top" style="white-space: nowrap;"><? echo $lang['profile_h_software']; ?> : </td>

<td class="text10b" align="center">

<table width='100%' border='0' align='center' cellpadding='0' cellspacing='0'>

<tr>

<td valign="top">

<?

if (isset($ph->softwares) && count($ph->softwares)) {

echo "<select size='10'>";

foreach ($ph->softwares as $soft)

echo "<option>". $soft ."</option>";

echo "</select>";

}

echo "";

if (isset($ph->softwaresUp) && count ($ph->softwaresUp)) {

echo "<select size='10'>";

foreach ($ph->softwaresUp as $softUp)

echo "<option>". $softUp ."</option>";

echo "</select>";

}

?>

</td>

</tr>

</table>

</td>

</tr>

<tr>

<td valign="top" style="white-space: nowrap;"><? echo $lang['profile_o_live_update']; ?> : </td>

<td class="text10b">

<table width='100%' border='0' align='center' cellpadding='0' cellspacing='0'>

<tr>

<td><? echo date("d/m/Y - H:i", $ph->get_update()); ?></td>

</tr>

</table>

</td>

</tr>

</table>

<? include ("tab3Bot.php"); ?>

</td>

</tr>

</table>

<? } ?>

</td>

</tr>

</table>

</td>

boubou
04-18-2005, 03:21 PM
Bonjour Esteban 135.

Je suis aussi sur MDK 10.1 et j'avais que des 0.
Je viens d'utiliser ton programme et ca m'affiche les bonnes données.

Bravo maestro :wink:

julio
04-18-2005, 03:43 PM
a mon avis ca varie en fonction des distrib... et des versions de snmp...

Depuis qu'on a mis en place tout cela ca ne marche plus. Va falloir trouver qq chose de plus generique...

en tout cas merci :)

Esteban135
04-18-2005, 04:46 PM
Salut julio,

Je penses qu'il faudrais plus ce diriger vers les fonctions Snmp de php.
Car les sorties d'infos doivent etre a mon avis identique sur n'importe quel distrib.

si tu veux je peut essayer de m'y pencher??

rom
04-18-2005, 05:09 PM
Ca ca serait cool ! :roll: :idea:

julio
04-18-2005, 05:09 PM
ha oui a mon avis en plus ca sera mieux formaté en output... je ne suis pas contre pour que tu te penches la dessus...