@@ -1389,68 +1389,79 @@ function plugin_ocsinventoryng_ruleCollectionPrepareInputDataForProcess($params)
1389
1389
1390
1390
$ ocsClient = PluginOcsinventoryngOcsServer::getDBocs ($ ocsservers_id );
1391
1391
1392
- $ tables = array_keys (plugin_ocsinventoryng_getTablesForQuery ($ params ['rule_itemtype ' ]));
1393
- $ fields = plugin_ocsinventoryng_getFieldsForQuery ($ params ['rule_itemtype ' ]);
1392
+ if (!isset ($ params ['values ' ]['input ' ]['type ' ])) {
1393
+ $ tables = array_keys (plugin_ocsinventoryng_getTablesForQuery ($ params ['rule_itemtype ' ]));
1394
+ $ fields = plugin_ocsinventoryng_getFieldsForQuery ($ params ['rule_itemtype ' ]);
1395
+
1396
+ $ ocsComputer = $ ocsClient ->getOcsComputer ($ ocsid , $ tables );
1397
+
1398
+ if (!is_null ($ ocsComputer ) && count ($ ocsComputer ) > 0 ) {
1399
+ if (isset ($ ocsComputer ['NETWORKS ' ])) {
1400
+ $ networks = $ ocsComputer ['NETWORKS ' ];
1401
+
1402
+ $ ipblacklist = Blacklist::getIPs ();
1403
+ $ macblacklist = Blacklist::getMACs ();
1404
+
1405
+ foreach ($ networks as $ data ) {
1406
+ if (isset ($ data ['IPSUBNET ' ])) {
1407
+ $ rule_parameters ['IPSUBNET ' ][] = $ data ['IPSUBNET ' ];
1408
+ }
1409
+ if (isset ($ data ['MACADDR ' ]) && !in_array ($ data ['MACADDR ' ], $ macblacklist )) {
1410
+ $ rule_parameters ['MACADDRESS ' ][] = $ data ['MACADDR ' ];
1411
+ }
1412
+ if (isset ($ data ['IPADDRESS ' ]) && !in_array ($ data ['IPADDRESS ' ], $ ipblacklist )) {
1413
+ $ rule_parameters ['IPADDRESS ' ][] = $ data ['IPADDRESS ' ];
1414
+ }
1415
+ }
1416
+ }
1417
+ $ ocs_data = [];
1394
1418
1395
- $ ocsComputer = $ ocsClient ->getOcsComputer ($ ocsid , $ tables );
1419
+ foreach ($ fields as $ field ) {
1420
+ // TODO cleaner way of getting fields
1421
+ $ field = explode ('. ' , $ field );
1422
+ if (count ($ field ) < 2 ) {
1423
+ continue ;
1424
+ }
1396
1425
1397
- if (!is_null ($ ocsComputer ) && count ($ ocsComputer ) > 0 ) {
1398
- if (isset ($ ocsComputer ['NETWORKS ' ])) {
1399
- $ networks = $ ocsComputer ['NETWORKS ' ];
1426
+ $ table = strtoupper ($ field [0 ]);
1400
1427
1401
- $ ipblacklist = Blacklist::getIPs ();
1402
- $ macblacklist = Blacklist::getMACs ();
1428
+ $ fieldSql = explode (' ' , $ field [1 ]);
1429
+ $ ocsField = $ fieldSql [0 ];
1430
+ $ glpiField = $ fieldSql [count ($ fieldSql ) - 1 ];
1403
1431
1404
- foreach ($ networks as $ data ) {
1405
- if (isset ($ data ['IPSUBNET ' ])) {
1406
- $ rule_parameters ['IPSUBNET ' ][] = $ data ['IPSUBNET ' ];
1407
- }
1408
- if (isset ($ data ['MACADDR ' ]) && !in_array ($ data ['MACADDR ' ], $ macblacklist )) {
1409
- $ rule_parameters ['MACADDRESS ' ][] = $ data ['MACADDR ' ];
1432
+ $ section = [];
1433
+ if (isset ($ ocsComputer [$ table ])) {
1434
+ $ section = $ ocsComputer [$ table ];
1410
1435
}
1411
- if (isset ($ data ['IPADDRESS ' ]) && !in_array ($ data ['IPADDRESS ' ], $ ipblacklist )) {
1412
- $ rule_parameters ['IPADDRESS ' ][] = $ data ['IPADDRESS ' ];
1436
+ if (array_key_exists ($ ocsField , $ section )) {
1437
+ // Not multi
1438
+ $ ocs_data [$ glpiField ][] = $ section [$ ocsField ];
1439
+ } else {
1440
+ foreach ($ section as $ sectionLine ) {
1441
+ $ ocs_data [$ glpiField ][] = $ sectionLine [$ ocsField ];
1442
+ }
1413
1443
}
1414
1444
}
1415
- }
1416
- $ ocs_data = [];
1417
1445
1418
- foreach ($ fields as $ field ) {
1419
- // TODO cleaner way of getting fields
1420
- $ field = explode ('. ' , $ field );
1421
- if (count ($ field ) < 2 ) {
1422
- continue ;
1423
- }
1424
-
1425
- $ table = strtoupper ($ field [0 ]);
1426
-
1427
- $ fieldSql = explode (' ' , $ field [1 ]);
1428
- $ ocsField = $ fieldSql [0 ];
1429
- $ glpiField = $ fieldSql [count ($ fieldSql ) - 1 ];
1430
-
1431
- $ section = [];
1432
- if (isset ($ ocsComputer [$ table ])) {
1433
- $ section = $ ocsComputer [$ table ];
1434
- }
1435
- if (array_key_exists ($ ocsField , $ section )) {
1436
- // Not multi
1437
- $ ocs_data [$ glpiField ][] = $ section [$ ocsField ];
1438
- } else {
1439
- foreach ($ section as $ sectionLine ) {
1440
- $ ocs_data [$ glpiField ][] = $ sectionLine [$ ocsField ];
1441
- }
1446
+ //This case should never happend but...
1447
+ //Sometimes OCS can't find network ports but fill the right ip in hardware table...
1448
+ //So let's use the ip to proceed rules (if IP is a criteria of course)
1449
+ if (in_array ("IPADDRESS " , $ fields ) && !isset ($ ocs_data ['IPADDRESS ' ])) {
1450
+ $ ocs_data ['IPADDRESS ' ]
1451
+ = PluginOcsinventoryngOcsProcess::getGeneralIpAddress ($ ocsservers_id , $ ocsid );
1442
1452
}
1453
+ return array_merge ($ rule_parameters , $ ocs_data );
1443
1454
}
1444
-
1445
- //This case should never happend but...
1446
- //Sometimes OCS can't find network ports but fill the right ip in hardware table...
1447
- //So let's use the ip to proceed rules (if IP is a criteria of course)
1448
- if ( in_array ( " IPADDRESS " , $ fields ) && ! isset ( $ ocs_data [ ' IPADDRESS ' ]) ) {
1449
- $ ocs_data ['IPADDRESS ' ]
1450
- = PluginOcsinventoryngOcsProcess:: getGeneralIpAddress ( $ ocsservers_id , $ ocsid );
1455
+ } else {
1456
+ // Set empty TAG (maybe use the snmp TAG accountinfo in the futur ?)
1457
+ $ rule_parameters [ ' TAG ' ][] = "" ;
1458
+ if ( isset ( $ params [ ' values ' ][ ' params ' ][ ' snmpdata ' ][ ' NetworkName__ipaddresses ' ])) {
1459
+ foreach ( $ params [ ' values ' ][ ' params ' ][ ' snmpdata ' ][ ' NetworkName__ipaddresses ' ] as $ key => $ ipaddress ) {
1460
+ $ rule_parameters ['IPADDRESS ' ][] = $ ipaddress ;
1461
+ }
1451
1462
}
1452
- return array_merge ($ rule_parameters , $ ocs_data );
1453
1463
1464
+ return $ rule_parameters ;
1454
1465
}
1455
1466
}
1456
1467
return [];
0 commit comments