Skip to content

Commit

Permalink
Merge pull request #1559 from OCSInventory-NG/ipd_snmp_reconciliation
Browse files Browse the repository at this point in the history
Ipd snmp reconciliation
  • Loading branch information
charleneauger authored Sep 25, 2023
2 parents 4964c81 + 43e2c20 commit 1946ee3
Show file tree
Hide file tree
Showing 8 changed files with 347 additions and 125 deletions.
3 changes: 3 additions & 0 deletions files/update/7077.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- Add IPD reconciliation field to snmp_configs table
UNLOCK TABLES;
ALTER TABLE `snmp_configs` ADD COLUMN `IPD_RECONCILIATION` VARCHAR(255) DEFAULT NULL;
5 changes: 4 additions & 1 deletion plugins/language/en_GB/en_GB.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1729,6 +1729,9 @@
9038 Number of equipment per type
9039 Quick view
9040 Export all SNMP types
9041 Use for IpDiscover reconciliation (must be an IP address OID)
9042 SNMP devices
9043 An IpDiscover reconciliation field is already set for this type

9100 SSL key path
9101 SSL certificat path
Expand Down Expand Up @@ -1847,9 +1850,9 @@
9701 CAS server uri, e.g : /cas
9702 CAS server host, e.g. : authentication.org
9703 CAS default role, applied on first connection initiated using CAS authentication
9704 CAS Configuration
9705 CAS Base URI, e.g. : ocs.example.com
9706 CAS Server CA Certificate Path, e.g. : /path/to/cachain.pem
9704 CAS Configuration

9800 Exclude archived computers from statistics, CVE inventory, all softwares count, computers per TAG count
9801 Show bios diagram in dashboard
Expand Down
3 changes: 3 additions & 0 deletions plugins/language/fr_FR/fr_FR.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1724,6 +1724,9 @@
9038 Nombre d'équipements par type
9039 Aperçu rapide
9040 Exporter tous les types SNMP
9041 Utiliser comme réconciliation pour l'IpDiscover (doit être une adresse IP)
9042 machines SNMP
9043 Un champ de réconciliation IpDiscover est déjà configuré pour ce type

9100 Chemin de la clé SSL
9101 Chemin du certificat SSL
Expand Down
10 changes: 7 additions & 3 deletions plugins/main_sections/ms_config/ms_snmp_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@
}

if(isset($protectedPost['update_snmp'])) {
$result = $snmp->snmp_config($protectedPost['type_id'], $protectedPost['label_id'], $protectedPost['oid'], $protectedPost['reconciliation'] ?? '');
$result = $snmp->snmp_config($protectedPost['type_id'], $protectedPost['label_id'], $protectedPost['oid'], $protectedPost['reconciliation'] ?? '', $protectedPost['ipd_reconciliation'] ?? '');
if($result == 0){
msg_success($l->g(572));
}else{
Expand All @@ -291,6 +291,7 @@
formGroup('select', 'label_id', 'Label :', '', '', '', '', $label, $label);
formGroup('text', 'oid', 'OID :', '', '', '', '', '', '', "");
formGroup('checkbox', 'reconciliation', $l->g(9015).' :', '', '', 'YES', '', '', '');
formGroup('checkbox', 'ipd_reconciliation', $l->g(9041).' :', '', '', 'YES', '', '', '');

echo "<input type='submit' name='update_snmp' id='update_snmp' class='btn btn-success' value='".$l->g(13)."'>";
echo "</br></br><hr></br>";
Expand All @@ -314,7 +315,8 @@
"Type" => 't.TYPE_NAME',
"Label" => 'l.LABEL_NAME',
"OID" => "c.OID",
"RECONCILIATION" => "c.RECONCILIATION"
"RECONCILIATION" => "c.RECONCILIATION",
"IPD_RECONCILIATION" => "c.IPD_RECONCILIATION",
);

$list_fields['SUP'] = 'c.ID';
Expand All @@ -323,7 +325,7 @@
$default_fields = $list_fields;
$list_col_cant_del = $list_fields;

$queryDetails = "SELECT DISTINCT c.ID, t.TYPE_NAME, l.LABEL_NAME, c.OID, c.RECONCILIATION FROM snmp_configs c
$queryDetails = "SELECT DISTINCT c.ID, t.TYPE_NAME, l.LABEL_NAME, c.OID, c.RECONCILIATION, c.IPD_RECONCILIATION FROM snmp_configs c
LEFT JOIN snmp_types t ON c.TYPE_ID = t.ID
LEFT JOIN snmp_labels l ON c.LABEL_ID = l.ID". $filter;

Expand Down Expand Up @@ -433,6 +435,7 @@
<th tabindex="0" aria-controls="affich_version" rowspan="1" colspan="1" style="width: 22%;" aria-label="Label"><font>'.$l->g(9018).'</font></th>
<th tabindex="0" aria-controls="affich_publisher" rowspan="1" colspan="1" style="width: 22%;" aria-label="Numeric OID"><font>'.$l->g(9017).'</font></th>
<th tabindex="0" aria-controls="affich_version" rowspan="1" colspan="1" style="width: 12%;" aria-label="Reconciliation"><font>'.$l->g(9015).'</font></th>
<th tabindex="0" aria-controls="affich_version" rowspan="1" colspan="1" style="width: 12%;" aria-label="IPDReconciliation"><font>'.$l->g(9041).'</font></th>
</tr>
</thead>
</table>
Expand All @@ -453,6 +456,7 @@
echo ' </td>';
echo ' <td valign="top" colspan="1" style="width: 22%; text-align:center;" class="affich_publisher">'.$oid.'<input class="form-control" type="hidden" name="oid_'.$name.'" value="'.$oid.'"></td>';
echo ' <td valign="top" colspan="1" style="width: 12%; text-align:center;" class="affich_publisher"><input type="checkbox" class="perso_checkbox" id="reconciliation_'.$name.'" name="reconciliation_'.$name.'" value="YES"></td>';
echo ' <td valign="top" colspan="1" style="width: 12%; text-align:center;" class="affich_publisher"><input type="checkbox" class="perso_checkbox" id="ipd_reconciliation_'.$name.'" name="ipd_reconciliation_'.$name.'" value="YES"></td>';
echo ' </tr>';
}

Expand Down
82 changes: 75 additions & 7 deletions plugins/main_sections/ms_ipdiscover/ms_custom_info.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
}

require_once('require/function_ipdiscover.php');
require_once('require/snmp/Snmp.php');

if (!isset($protectedPost['MODIF']) || (isset($protectedPost['MODIF']) && $protectedPost['MODIF'] == "")) {
echo "<a class='btn btn-info' href='index.php?function=show_ipdiscover'>".$l->g(188)."</a></br></br>";
Expand Down Expand Up @@ -184,6 +185,11 @@
if (!(isset($protectedPost["pcparpage"]))) {
$protectedPost["pcparpage"] = 5;
}

// SNMP filtering
$snmp = new OCSSnmp();
$snmpTables = $snmp->getIPDReconciliationColumns();

if (isset($protectedGet['value'])) {
$explode = explode(";", $protectedGet['value']);
$value_preg = preg_replace("/[^A-zA-Z0-9\._]/", "", $explode[0]);
Expand All @@ -192,14 +198,30 @@
if ($protectedGet['prov'] == "no_inv") {
$title = $l->g(947);
$sql = "SELECT
ip, mac, mask, date, name, n.TAG
ip, mac, mask, date, n.name, n.TAG
FROM netmap n
LEFT JOIN networks ns ON ns.macaddr=n.mac
WHERE n.mac NOT IN (
SELECT DISTINCT(macaddr) FROM network_devices
)
AND (ns.macaddr IS NULL)
AND n.netid IN ('%s')";
LEFT JOIN networks ns ON ns.macaddr=n.mac";
// left join for SNMP tables (excludes SNMP devices)
if ($snmpTables) {
foreach ($snmpTables as $snmpTable) {
$sql .= " LEFT JOIN $snmpTable[TABLE_TYPE_NAME] ON $snmpTable[TABLE_TYPE_NAME].$snmpTable[LABEL_NAME] = n.IP ";
}
}
$sql .= " WHERE ";
// adding WHERE clause for SNMP tables (excludes SNMP devices)
if ($snmpTables) {
foreach($snmpTables as $snmpTable) {
// we want devices which are not in SNMP tables
$sql .= " $snmpTable[TABLE_TYPE_NAME].$snmpTable[LABEL_NAME] IS NULL AND ";
}
}

$sql .= " n.mac NOT IN (
SELECT DISTINCT(macaddr) FROM network_devices
)
AND (ns.macaddr IS NULL)
AND n.netid IN ('%s')";

if($tag != "") {
$sql .= " AND n.TAG = '%s'";
}
Expand Down Expand Up @@ -300,7 +322,53 @@
$tab_options['FILTRE']['h.userid'] = $l->g(24);
$tab_options['FILTRE']['h.osname'] = $l->g(25);
$tab_options['FILTRE']['h.ipaddr'] = $l->g(34);
} else if ($protectedGet['prov'] == "snmp") {
// display IPD discovered devices who are also in SNMP tables
$title = $l->g(9042);

$list_fields = array(
$l->g(34) => 'IP',
$l->g(95) => 'MAC',
$l->g(208) => 'MASK',
$l->g(316) => 'NETID',
$l->g(318) => 'n.NAME',
$l->g(232) => 'date',
'TAG' => 'TAG'
);

$sql = prepare_sql_tab($list_fields);
$tab_options['ARG_SQL'] = $sql['ARG'];

$snmp = new OCSSnmp();
$snmpTables = $snmp->getIPDReconciliationColumns();

$sql = prepare_sql_tab($list_fields);
$list_fields = array_merge($list_fields, array('TYPE' => "TYPE"));
$default_fields = $list_fields;
$sql = $sql['SQL'] . ",CASE ";

$case = "";
$leftjoin = "";
foreach ($snmpTables as $snmpTable) {
$case .= "WHEN $snmpTable[TABLE_TYPE_NAME].$snmpTable[LABEL_NAME] IS NOT NULL THEN '$snmpTable[TABLE_TYPE_NAME]' ";
$leftjoin .= " LEFT JOIN $snmpTable[TABLE_TYPE_NAME] ON $snmpTable[TABLE_TYPE_NAME].$snmpTable[LABEL_NAME] = n.IP ";
}
$sql .= $case." ELSE 'Unknown'
END AS `TYPE` FROM netmap n
".$leftjoin."
WHERE (";
foreach($snmpTables as $snmpTable) {
$sql .= " $snmpTable[TABLE_TYPE_NAME].$snmpTable[LABEL_NAME] IS NOT NULL OR ";
}
$sql = substr($sql, 0, -3);
$sql .= ") AND n.netid = '%s'";
if($tag != "") {
$sql .= " AND n.TAG = '%s'";
}
array_push($tab_options['ARG_SQL'], $value_preg, $tag);
$tab_options['ARG_SQL_COUNT'] = array($value_preg, $tag);
}

printEnTete($title);
echo "<br><br>";

Expand Down
Loading

0 comments on commit 1946ee3

Please sign in to comment.