Hi, I add a zone with IP 192.168.2.0/24 and

manually running jffnms/engine$ php -q autodiscovery_network.php master
5

the nad_networks table has the following record.

+----+--------------------+------+-------------+--------+------+--------
-------------+
| id | network | deep | oper_status | parent | seed |
oper_status_changed |
+----+--------------------+------+-------------+--------+------+--------
-------------+
| 1 | 127.255.255.255/22 | 1 | 0 | 1 | 2 |
1131113262 |
+----+--------------------+------+-------------+--------+------+--------
-------------+

The nad_ips and nad_hosts tables are empty.

Again running manually, the table nad_networks has the following
records:
+----+--------------------+------+-------------+--------+------+--------
-------------+
| id | network | deep | oper_status | parent | seed |
oper_status_changed |
+----+--------------------+------+-------------+--------+------+--------
-------------+
| 1 | 127.255.255.255/22 | 1 | 0 | 1 | 2 |
1131114074 |
| 2 | 127.255.255.255/22 | 1 | 3 | 1 | 2 |
1131114119 |
+----+--------------------+------+-------------+--------+------+--------
-------------+

and the tables nad* are non empty with wrong value.

I do some changes to the file autodiscovery_network.php and now the
NAD works almost well
om my network. There is another bug: some hosts are not displayed.

Can you test my module on your networks?
The changes are:

--- autodiscovery_network.php   2005-11-07 11:53:27.384740520 +0100
+++ autodiscovery_network.php.good      2005-11-07 12:08:42.794577072 +0100
@@ -35,7 +35,7 @@
     }

     function ip_to_str2 ($ip_ip) {
-       $ip_bin = decbin($ip_ip);
+       $ip_bin =  base_convert($ip_ip, 10, 2);
        $ip_bin = str_pad($ip_bin,32,"0",STR_PAD_LEFT);
        $parte1 = substr($ip_bin,0,8);
         $parte2 = substr($ip_bin,8,8);
@@ -57,7 +57,10 @@
     }

     function bitsmask_to_mask ($bmask) {
-       $b = round(pow(2,32) - pow(2,32 - $bmask));
+        $appo = 32 - $bmask;
+        $appo1 = pow(2,32);
+        $appo2 = pow(2,$appo);
+        $b = $appo1 -$appo2;
        $b = ip_to_str2 ($b);
        return $b;
     }
@@ -85,7 +89,9 @@

            if  (
                (ip_same_network($net, $private_net, 
bitsmask_to_mask($private_mask))) ||       // base net is the same network as a 
private net
-               (ip_same_network($net, "0.0.0.0", bitsmask_to_mask($net_mask))) 
                // base net is 0.0.0.0
+               (ip_same_network($net, "0.0.0.0", bitsmask_to_mask($net_mask))) 
||              // base net is 0.0.0.0
+               (ip_same_network($net, "0.0.0.0", bitsmask_to_mask(24)))        
                // base net is 0.0.0.0
+
                )
                return true;
        }
@@ -117,7 +123,9 @@
        $hosts_up = 0;
        $hosts_unique = 0;

-       $net_data = current(nad_load_networks($network));
+       $tmp_data = nad_load_networks($network);
+       $net_data = current($tmp_data);
+

        if (!$output) ob_start();

@@ -204,6 +213,9 @@

                    // Create IPs Table
                    foreach ($snmp_ips_data as $key=>$aux_ip) {
+                       $aux_ip = trim($aux_ip);
+
+                       if (strpos(" ", $aux_ip)!==false)
                        list(,$aux_ip) = explode (" ",$aux_ip);

                        if (!in_array($aux_ip,$invalid_ips)) {
@@ -225,13 +237,16 @@
                    // Populate the IPs table with Mask and Type data
                    foreach ($host_ips as $aux_ip=>$ipd) {

+                       if (strpos(" ", $aux_mask)!==false)
                        list(,$aux_mask) = explode (" 
",$snmp_mask_data[$ipd["pos"]]);
+                       else
+                           $aux_mask = $snmp_mask_data[$ipd["pos"]];
+
                        if (empty($aux_mask)) $aux_mask = "255.255.255.0"; // 
Fix for broken IP-MIB implementations

                        $if_index = $snmp_int_data[$ipd["pos"]];
                        list(,$if_status) = split("[()]",snmp_get($host_ip, 
$comm, $intstatus_oid.".".$if_index));

-                       //$if_status = 1;
                        if ($if_status == 1) { // Its UP
                            unset ($if_type);
                            list(,$if_type) = split("[()]",snmp_get($host_ip, 
$comm, $inttype_oid.".".$if_index));
@@ -323,10 +341,11 @@
            $ip_bit = str_to_ip($ip);
            $mask_bit = str_to_ip($mask);

-           $net_bit = $ip_bit & $mask_bit;
+           $net_bit = base_convert((   (base_convert($ip_bit,10,2)) & 
(base_convert($mask_bit, 10, 2))), 2, 10);
+
            $net = ip_to_str2 ($net_bit);

-           if ($net != "127.0.0.0") {
+           if ( ($net != "127.0.0.0")  && ($net!="0.0.0.0")) {
                $oper_status = 0;

                $mask_prefix = ip_to_bitsmask ($mask_bit);
@@ -348,11 +367,23 @@
                      "via NET_ID $parent_net, Deep $deep\n");
                 */

-               if (!isset($networks[$aux]))
-                   return db_insert("nad_networks",array("network"=>$aux, 
"deep"=>$deep, "parent"=>$parent_net,
-                       "oper_status"=>$oper_status, "seed"=>$seed_id, 
"oper_status_changed"=>time(), "id"=>$id));
-               else
-                   return $networks[$aux]["id"];       // return the network id
+               if (!isset($networks[$aux])) {
+
+                   $fields = array("network"=>$aux, "deep"=>$deep, 
"parent"=>$parent_net,
+                       "oper_status"=>$oper_status, "seed"=>$seed_id, 
"oper_status_changed"=>time());
+
+                   if ($id!==NULL) $fields["id"] = $id;
+
+                       $appo = db_insert("nad_networks",$fields);
+
+                       return $appo;
+
+               } else
+               {
+                   $appo =  $networks[$aux]["id"];     // return the network 
ida
+
+                       return $appo;
+               }
            }
     }

@@ -469,7 +500,8 @@
        db_repair("nad_hosts");
        db_repair("nad_ips");

-       nad_load_seeds(nad_load_networks());
+       $tmp_networks = nad_load_networks();
+       nad_load_seeds($tmp_networks);

        return true;
     }
@@ -555,7 +587,7 @@
                if (($net_data["oper_status"] == 2) &&                          
        // if its Running
                    !isset($pending_items[$network])) {                         
        // and its not in the pending list

-                   nad_network_status ($net_data["id"], 5);                    
        // mark it as error
+                   //nad_network_status ($net_data["id"], 5);                  
        // mark it as error
                    logger("Changed Network $network to Error, because it was 
hanged running\n");
                }




-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
jffnms-users mailing list
jffnms-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jffnms-users

Reply via email to