Skip to content

Commit

Permalink
Also collect the system uptime
Browse files Browse the repository at this point in the history
  • Loading branch information
Hipska committed Jun 21, 2024
1 parent 7817537 commit be65685
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
7 changes: 7 additions & 0 deletions json/SnmpDiscoveryCollector.json
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,13 @@
"update_policy": "master_locked",
"finalclass": "SynchroAttribute"
},
{
"attcode": "snmp_sysUptime",
"update": "1",
"reconcile": "0",
"update_policy": "master_locked",
"finalclass": "SynchroAttribute"
},
{
"attcode": "snmpcredentials_id",
"update": "1",
Expand Down
2 changes: 1 addition & 1 deletion module.snmp-discovery-collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

SetupWebPage::AddModule(
__FILE__, // Path to the current file, all other file names are relative to the directory containing this file
'snmp-discovery-collector/1.3.2',
'snmp-discovery-collector/1.4.0',
[]
);
11 changes: 8 additions & 3 deletions src/SnmpDiscoveryCollector.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function Init(): void
parent::Init();

// Check if modules are installed
Utils::CheckModuleInstallation('sv-snmp-discovery', true);
Utils::CheckModuleInstallation('sv-snmp-discovery/1.2.0', true);

// Load SNMP discovery application settings
$this->LoadApplicationSettings();
Expand Down Expand Up @@ -122,6 +122,7 @@ protected function HeaderIsAllowed(string $sHeader): bool
'snmp_sysdescr',
'snmp_syslocation',
'snmp_syscontact',
'snmp_sysuptime',
])) return true;

/**
Expand Down Expand Up @@ -347,8 +348,9 @@ protected static function LoadSnmpCredentials(int $iKey): SnmpCredentials
* snmp_last_discovery: string,
* snmp_sysname: string,
* snmp_sysdescr: string,
* snmp_syscontact: string,
* snmp_syslocation: string,
* snmp_syscontact: string,
* snmp_sysuptime: int,
* }|null
* @throws Exception
*/
Expand Down Expand Up @@ -402,11 +404,13 @@ protected function DiscoverDeviceByIP(int $iKey): ?array
// Load system table info
[
'.1.3.6.1.2.1.1.1.0' => $sSysDescr,
'.1.3.6.1.2.1.1.3.0' => $sSysUptime,
'.1.3.6.1.2.1.1.4.0' => $sSysContact,
'.1.3.6.1.2.1.1.5.0' => $sSysName,
'.1.3.6.1.2.1.1.6.0' => $sSysLocation,
] = @$oSNMP->get([
/* SNMPv2-MIB::sysDescr */ '.1.3.6.1.2.1.1.1.0',
/* SNMPv2-MIB::sysUptime */ '1.3.6.1.2.1.1.3.0',
/* SNMPv2-MIB::sysContact */ '.1.3.6.1.2.1.1.4.0',
/* SNMPv2-MIB::sysName */ '.1.3.6.1.2.1.1.5.0',
/* SNMPv2-MIB::sysLocation */ '.1.3.6.1.2.1.1.6.0',
Expand All @@ -426,8 +430,9 @@ protected function DiscoverDeviceByIP(int $iKey): ?array
'snmp_last_discovery' => date(Utils::GetConfigurationValue('date_format', 'Y-m-d H:i:s')),
'snmp_sysname' => $sSysName,
'snmp_sysdescr' => trim($sSysDescr),
'snmp_syscontact' => $sSysContact,
'snmp_syslocation' => $sSysLocation,
'snmp_syscontact' => $sSysContact,
'snmp_sysuptime' => (int) round($sSysUptime/100),
];
}
}
Expand Down

0 comments on commit be65685

Please sign in to comment.