mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
SNMP enhancements #718
This commit is contained in:
@@ -31,7 +31,11 @@
|
|||||||
{
|
{
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
.logs-row button{
|
.logs-row .button-wrap{
|
||||||
|
/* margin: 2px; */
|
||||||
|
|
||||||
|
}
|
||||||
|
.logs-row .button{
|
||||||
margin: 2px;
|
margin: 2px;
|
||||||
}
|
}
|
||||||
.logs-row
|
.logs-row
|
||||||
|
|||||||
@@ -29,16 +29,26 @@ function renderLogArea($params) {
|
|||||||
|
|
||||||
// Prepare buttons HTML
|
// Prepare buttons HTML
|
||||||
$buttonsHtml = '';
|
$buttonsHtml = '';
|
||||||
|
$totalButtons = count($buttons);
|
||||||
|
if ($totalButtons > 0) {
|
||||||
|
$colClass = 12 / $totalButtons;
|
||||||
|
// Use $colClass in your HTML generation or further logic
|
||||||
|
} else {
|
||||||
|
// Handle case where $buttons array is empty
|
||||||
|
$colClass = 12;
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($buttons as $button) {
|
foreach ($buttons as $button) {
|
||||||
$labelStringCode = isset($button['labelStringCode']) ? $button['labelStringCode'] : '';
|
$labelStringCode = isset($button['labelStringCode']) ? $button['labelStringCode'] : '';
|
||||||
$event = isset($button['event']) ? $button['event'] : '';
|
$event = isset($button['event']) ? $button['event'] : '';
|
||||||
|
|
||||||
$buttonsHtml .= '
|
$buttonsHtml .= '
|
||||||
<div class="col-sm-6 col-xs-6">
|
<div class="button-wrap col-sm-' . $colClass . ' col-xs-' . $colClass . '">
|
||||||
<button class="btn btn-primary" onclick="' . htmlspecialchars($event) . '">' . lang($labelStringCode) . '</button>
|
<button class="btn btn-primary col-sm-12 col-xs-12" onclick="' . htmlspecialchars($event) . '">' . lang($labelStringCode) . '</button>
|
||||||
</div>';
|
</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Render the log area HTML
|
// Render the log area HTML
|
||||||
$html = '
|
$html = '
|
||||||
<div class="log-area box box-solid box-primary">
|
<div class="log-area box box-solid box-primary">
|
||||||
@@ -48,12 +58,12 @@ function renderLogArea($params) {
|
|||||||
'</textarea>
|
'</textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="row logs-row">
|
<div class="row logs-row">
|
||||||
<div class="log-file col-sm-8 col-xs-12">' . htmlspecialchars($fileName) . '
|
<div class="log-file col-sm-6 col-xs-12">' . htmlspecialchars($fileName) . '
|
||||||
<div class="logs-size">' . number_format((filesize($filePath) / 1000000), 2, ",", ".") . ' MB'
|
<div class="logs-size">' . number_format((filesize($filePath) / 1000000), 2, ",", ".") . ' MB'
|
||||||
. $downloadButtonHtml .
|
. $downloadButtonHtml .
|
||||||
'</div>
|
'</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-4 col-xs-12">'
|
<div class="col-sm-6 col-xs-12">'
|
||||||
. $buttonsHtml .
|
. $buttonsHtml .
|
||||||
'</div>
|
'</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
2
front/php/templates/language/es_es.json
Normal file → Executable file
2
front/php/templates/language/es_es.json
Normal file → Executable file
@@ -767,4 +767,4 @@
|
|||||||
"settings_update_item_warning": "Actualice el valor a continuación. Tenga cuidado de seguir el formato anterior. <b>O la validación no se realiza.</b>",
|
"settings_update_item_warning": "Actualice el valor a continuación. Tenga cuidado de seguir el formato anterior. <b>O la validación no se realiza.</b>",
|
||||||
"test_event_icon": "fa-vial-circle-check",
|
"test_event_icon": "fa-vial-circle-check",
|
||||||
"test_event_tooltip": "Guarda tus cambios antes de probar nuevos ajustes."
|
"test_event_tooltip": "Guarda tus cambios antes de probar nuevos ajustes."
|
||||||
}
|
}
|
||||||
@@ -687,4 +687,4 @@
|
|||||||
"settings_update_item_warning": "Aggiorna il valore qui sotto. Fai attenzione a seguire il formato precedente. <b>La convalida non viene eseguita.</b>",
|
"settings_update_item_warning": "Aggiorna il valore qui sotto. Fai attenzione a seguire il formato precedente. <b>La convalida non viene eseguita.</b>",
|
||||||
"test_event_icon": "fa-vial-circle-check",
|
"test_event_icon": "fa-vial-circle-check",
|
||||||
"test_event_tooltip": "Salva le modifiche prima di provare le nuove impostazioni."
|
"test_event_tooltip": "Salva le modifiche prima di provare le nuove impostazioni."
|
||||||
}
|
}
|
||||||
2
front/php/templates/language/pl_pl.json
Normal file → Executable file
2
front/php/templates/language/pl_pl.json
Normal file → Executable file
@@ -687,4 +687,4 @@
|
|||||||
"settings_update_item_warning": "Zaktualizuj poniższą wartość. Zachowaj ostrożność i postępuj zgodnie z poprzednim formatem. <b>Walidacja nie jest wykonywana.</b>",
|
"settings_update_item_warning": "Zaktualizuj poniższą wartość. Zachowaj ostrożność i postępuj zgodnie z poprzednim formatem. <b>Walidacja nie jest wykonywana.</b>",
|
||||||
"test_event_icon": "fa-vial-circle-check",
|
"test_event_icon": "fa-vial-circle-check",
|
||||||
"test_event_tooltip": "Zapisz zmiany zanim będziesz testować swoje ustawienia."
|
"test_event_tooltip": "Zapisz zmiany zanim będziesz testować swoje ustawienia."
|
||||||
}
|
}
|
||||||
@@ -1,17 +1,19 @@
|
|||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
A plugin for importing devices from an SNMP enabled router or switch. Using SNMP offers an efficient way to discover IPv4 devices across one or more networks/subnets/vlans.
|
A plugin for importing devices from an SNMP-enabled router or switch. Using SNMP offers an efficient way to discover IPv4 devices across one or more networks/subnets/vlans.
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
Specify the following settings in the Settings section of NetAlertX:
|
Specify the following settings in the Settings section of NetAlertX:
|
||||||
|
|
||||||
- `SNMPDSC_routers` - A list of `snmpwalk` commands to execute against IP addresses of roputers/switches with SNMP turned on. For example:
|
- `SNMPDSC_routers` - A list of `snmpwalk` commands to execute against IP addresses of routers/switches with SNMP turned on. For example:
|
||||||
|
|
||||||
- `snmpwalk -v 2c -c public -OXsq 192.168.1.1 .1.3.6.1.2.1.3.1.1.2`
|
- `snmpwalk -v 2c -c public -OXsq 192.168.1.1 .1.3.6.1.2.1.3.1.1.2`
|
||||||
- `snmpwalk -v 2c -c public -Oxsq 192.168.1.1 .1.3.6.1.2.1.3.1.1.2` (note: lower case `x`)
|
- `snmpwalk -v 2c -c public -Oxsq 192.168.1.1 .1.3.6.1.2.1.3.1.1.2` (note: lower case `x`)
|
||||||
|
|
||||||
|
|
||||||
|
If unsure, please check [snmpwalk examples](https://www.comparitech.com/net-admin/snmpwalk-examples-windows-linux/).
|
||||||
|
|
||||||
### Setup Cisco IOS
|
### Setup Cisco IOS
|
||||||
|
|
||||||
Enable IOS SNMP service and restrict to selected (internal) IP/Subnet.
|
Enable IOS SNMP service and restrict to selected (internal) IP/Subnet.
|
||||||
@@ -35,5 +37,24 @@ show snmp
|
|||||||
### Notes
|
### Notes
|
||||||
|
|
||||||
- Only IPv4 supported.
|
- Only IPv4 supported.
|
||||||
- The SNMP OID `.1.1.1.3.6.1.2.1.3.1.1.2` is specifically for devices IPv4 ARP table. This OID has been tested on Cisco ISRs and other L3 devices. Support may vary between other vendors / devices.
|
- The SNMP OID `.1.1.1.3.6.1.2.1.3.1.1.2` is specifically for devices IPv4 ARP table. This OID has been tested on Cisco ISRs and other L3 devices. Support may vary between other vendors/devices.
|
||||||
- Expected output (ingestion) in format `iso.3.6.1.2.1.3.1.1.2.3.1.192.168.1.2 "6C 6C 6C 6C 6C 6C "`.
|
- Expected output (ingestion) in formats:
|
||||||
|
|
||||||
|
- `iso.3.6.1.2.1.3.1.1.2.3.1.192.168.1.2 "6C 6C 6C 6C 6C 6C "`.
|
||||||
|
- `ipNetToMediaPhysAddress[3][192.168.1.9] 6C:6C:6C:6C:6C:b6C1`.
|
||||||
|
|
||||||
|
|
||||||
|
### Finding your OID
|
||||||
|
|
||||||
|
- Ssh into the router (in this example the IP of the router is `192.168.1.1`)
|
||||||
|
- On the router execute `snmptranslate -On -IR ipNetToMediaPhysAddress` (This is a UniFi router example, and the `object_id` is `ipNetToMediaPhysAddress`. This might vary between vendors, google your router manufacturer examples.)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
jokob@SecurityGateway-USG:~$ snmptranslate -On -IR ipNetToMediaPhysAddress
|
||||||
|
.1.3.6.1.2.1.4.22.1.2
|
||||||
|
```
|
||||||
|
|
||||||
|
- Use the `snmpwalk -v 2c -OXsq -c public 192.168.1.1 .1.3.6.1.2.1.4.22.1.2` command in NetAlertX
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -60,11 +60,9 @@ def main():
|
|||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
|
|
||||||
tmpSplt = line.split('"')
|
tmpSplt = line.split('"')
|
||||||
|
|
||||||
|
|
||||||
if len(tmpSplt) == 3:
|
if len(tmpSplt) == 3:
|
||||||
|
|
||||||
|
|
||||||
ipStr = tmpSplt[0].split('.')[-4:] # Get the last 4 elements to extract the IP
|
ipStr = tmpSplt[0].split('.')[-4:] # Get the last 4 elements to extract the IP
|
||||||
macStr = tmpSplt[1].strip().split(' ') # Remove leading/trailing spaces from MAC
|
macStr = tmpSplt[1].strip().split(' ') # Remove leading/trailing spaces from MAC
|
||||||
@@ -86,6 +84,26 @@ def main():
|
|||||||
else:
|
else:
|
||||||
mylog('verbose', [f'[SNMPDSC] ipStr does not seem to contain a valid IP:', ipStr])
|
mylog('verbose', [f'[SNMPDSC] ipStr does not seem to contain a valid IP:', ipStr])
|
||||||
|
|
||||||
|
|
||||||
|
elif line.startswith('ipNetToMediaPhysAddress'):
|
||||||
|
# Format: snmpwalk -OXsq output
|
||||||
|
parts = line.split()
|
||||||
|
if len(parts) == 2:
|
||||||
|
|
||||||
|
ipAddress = parts[0].split('[')[-1][:-1]
|
||||||
|
macAddress = parts[1]
|
||||||
|
|
||||||
|
mylog('verbose', [f'[SNMPDSC] IP: {ipAddress} MAC: {macAddress}'])
|
||||||
|
|
||||||
|
plugin_objects.add_object(
|
||||||
|
primaryId = handleEmpty(macAddress),
|
||||||
|
secondaryId = handleEmpty(ipAddress.strip()),
|
||||||
|
watched1 = '(unknown)',
|
||||||
|
watched2 = handleEmpty(snmpwalkArgs[6]),
|
||||||
|
extra = handleEmpty(line),
|
||||||
|
foreignKey = handleEmpty(macAddress)
|
||||||
|
)
|
||||||
|
|
||||||
mylog('verbose', ['[SNMPDSC] Entries found: ', len(plugin_objects)])
|
mylog('verbose', ['[SNMPDSC] Entries found: ', len(plugin_objects)])
|
||||||
|
|
||||||
plugin_objects.write_result_file()
|
plugin_objects.write_result_file()
|
||||||
|
|||||||
Reference in New Issue
Block a user