Fix polling and discovery of FortiGate cluster sensors (#13980)

This commit is contained in:
Marvin Kuurstra 2022-05-19 23:01:43 +02:00 committed by GitHub
parent f71f5d0340
commit 28a5811923
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 28344 additions and 24522 deletions

View File

@ -46,3 +46,50 @@ foreach ($session_rate as $descr => $oid) {
$result
);
}
// Sensors for clusters
$fgHaSystemMode_txt = 'fgHaSystemMode.0';
$systemMode = snmp_get($device, $fgHaSystemMode_txt, '-Ovq', 'FORTINET-FORTIGATE-MIB');
if ($systemMode == 'activePassive' || $systemMode == 'activeActive') {
// Contains the indexes of all the cluster members
$fgHaStatsIndex_num = '.1.3.6.1.4.1.12356.101.13.2.1.1.1';
$fgHaStatsIndex_txt = 'fgHaStatsIndex';
// Fetch the cluster members
$haStatsEntries = snmpwalk_cache_multi_oid($device, $fgHaStatsIndex_txt, [], 'FORTINET-FORTIGATE-MIB');
// Count of results is the amount of cluster members
$clusterMemberCount = count($haStatsEntries);
// Create a count sensor and set warning to current cluster count
discover_sensor(
$valid['sensor'],
'count',
$device,
$fgHaStatsIndex_num,
$fgHaStatsIndex_txt,
'clusterState',
'Cluster State',
1,
1,
null,
$clusterMemberCount,
null,
null,
$result
);
}
unset(
$session_rate,
$descr,
$oid,
$oid_num,
$oid_txt,
$result,
$fgHaSystemMode_txt,
$fgHaStatsIndex_num,
$fgHaStatsIndex_txt,
$haStatsEntries,
$clusterMemberCount
);

View File

@ -23,59 +23,30 @@
* @author Patrik Jonsson <patrik.jonsson@gmail.com>
*/
$index = 0;
$fgHaSystemModeOid = 'fgHaSystemMode.0';
$systemMode = snmp_get($device, $fgHaSystemModeOid, '-Ovq', 'FORTINET-FORTIGATE-MIB');
$fgHaSystemMode_num = '.1.3.6.1.4.1.12356.101.13.1.1.0';
$fgHaSystemMode_txt = 'fgHaSystemMode.0';
$systemMode = snmp_get($device, $fgHaSystemMode_txt, '-Ovq', 'FORTINET-FORTIGATE-MIB');
// Verify that the device is clustered
if ($systemMode == 'activePassive' || $systemMode == 'activeActive') {
$fgHaStatsEntryOid = 'fgHaStatsEntry';
// Indexes of all the members
$fgHaStatsIndex_num = '.1.3.6.1.4.1.12356.101.13.2.1.1.1';
$fgHaStatsIndex_txt = 'fgHaStatsIndex';
// Fetch the cluster members
$haStatsEntries = snmpwalk_cache_multi_oid($device, $fgHaStatsEntryOid, [], 'FORTINET-FORTIGATE-MIB');
$haStatsEntries = snmpwalk_cache_multi_oid($device, $fgHaStatsIndex_txt, [], 'FORTINET-FORTIGATE-MIB');
if (is_array($haStatsEntries)) {
$stateName = 'clusterState';
$descr = 'Cluster State';
$states = [
['value' => 0, 'generic' => 2, 'graph' => 0, 'descr' => 'CRITICAL'],
['value' => 1, 'generic' => 0, 'graph' => 1, 'descr' => 'OK'],
];
create_state_index($stateName, $states);
$clusterMemberCount = count($haStatsEntries);
// If the device is part of a cluster but the member count is 1 the cluster has issues
$clusterState = $clusterMemberCount == 1 ? 0 : 1;
discover_sensor(
$valid['sensor'],
'state',
$device,
$fgHaSystemModeOid,
$index,
$stateName,
$descr,
1,
1,
null,
null,
null,
null,
$clusterState,
'snmp',
null,
null,
null,
'HA'
);
create_sensor_to_state_index($device, $stateName, $index);
foreach ($haStatsEntries as $index => $entry) {
// Get name of cluster member
$fgHaStatsHostname_txt = 'fgHaStatsHostname.' . $index;
$cluster_member_name = snmp_get($device, $fgHaStatsHostname_txt, '-Ovq', 'FORTINET-FORTIGATE-MIB');
// Setup a sensor for the cluster sync state
$stateName = 'haSyncStatus';
$descr = 'HA sync status';
$fgHaStatsSyncStatus_num = '.1.3.6.1.4.1.12356.101.13.2.1.1.12';
$fgHaStatsSyncStatus_txt = 'fgHaStatsSyncStatus';
$stateName = 'haSyncStatus ' . $index;
$descr = 'HA sync status ' . $cluster_member_name;
$states = [
['value' => 0, 'generic' => 2, 'graph' => 0, 'descr' => 'Out Of Sync'],
['value' => 1, 'generic' => 0, 'graph' => 1, 'descr' => 'In Sync'],
@ -88,8 +59,8 @@ if ($systemMode == 'activePassive' || $systemMode == 'activeActive') {
$valid['sensor'],
'state',
$device,
$fgHaStatsEntryOid,
$index,
$fgHaStatsSyncStatus_num . '.' . $index,
$fgHaStatsSyncStatus_txt . '.' . $index,
$stateName,
$descr,
1,
@ -112,9 +83,13 @@ if ($systemMode == 'activePassive' || $systemMode == 'activeActive') {
unset(
$index,
$fgHaSystemModeOid,
$fgHaSystemMode_num,
$fgHaSystemMode_txt,
$systemMode,
$fgHaStatsEntryOid,
$fgHaStatsIndex_num,
$fgHaStatsIndex_txt,
$fgHaStatsSyncStatus_num,
$fgHaStatsSyncStatus_txt,
$haStatsEntries,
$stateName,
$descr,

View File

@ -0,0 +1,19 @@
<?php
if ($sensor['sensor_type'] === 'clusterState') {
// Contains the indexes of all the cluster members
$fgHaStatsIndex_num = '.1.3.6.1.4.1.12356.101.13.2.1.1.1';
$fgHaStatsIndex_txt = 'fgHaStatsIndex';
// Fetch the cluster members
$haStatsEntries = snmpwalk_cache_multi_oid($device, $fgHaStatsIndex_txt, [], 'FORTINET-FORTIGATE-MIB');
// Count of results is the amount of cluster members
$sensor_value = count($haStatsEntries);
}
unset(
$fgHaStatsIndex_num,
$fgHaStatsIndex_txt,
$haStatsEntries,
);

View File

@ -1,58 +0,0 @@
<?php
/**
* fortigate.inc.php
*
* LibreNMS state sensor state polling module for Fortigate Firewalls
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* @link https://www.librenms.org
*
* @copyright 2020 Net Entertainment AB
* @author Patrik Jonsson <patrik.jonsson@gmail.com>
*/
if ($device['os'] == 'fortigate') {
if (in_array($sensor['sensor_type'], ['clusterState', 'haSyncStatus'])) {
// Fetch the cluster members and their data
$fgHaStatsEntryOid = 'fgHaStatsEntry';
$haStatsEntries = snmpwalk_cache_multi_oid($device, $fgHaStatsEntryOid, [], 'FORTINET-FORTIGATE-MIB');
if ($sensor['sensor_type'] == 'clusterState') {
// Determine if the cluster contains more than 1 device
$clusterState = 0;
if (is_array($haStatsEntries)) {
$clusterMemberCount = count($haStatsEntries);
$clusterState = $clusterMemberCount == 1 ? 0 : 1;
}
$sensor_value = $clusterState;
} elseif ($sensor['sensor_type'] == 'haSyncStatus') {
// 0 = Out of sync, 1 = In Sync, 2 = No Peer
$synchronized = 1;
$clusterMemberCount = count($haStatsEntries);
if ($clusterMemberCount == 1) {
$synchronized = 2;
} else {
foreach ($haStatsEntries as $entry) {
if ($entry['fgHaStatsSyncStatus'] == 'unsynchronized') {
$synchronized = 0;
}
}
}
$sensor_value = $synchronized;
}
unset($fgHaStatsEntryOid, $haStatsEntries, $clusterMemberCount, $synchronized, $clusterState, $clusterMemberCount);
}
}

View File

@ -41,6 +41,30 @@
"sensors": {
"discovery": {
"sensors": [
{
"sensor_deleted": 0,
"sensor_class": "count",
"poller_type": "snmp",
"sensor_oid": ".1.3.6.1.4.1.12356.101.13.2.1.1.1",
"sensor_index": "fgHaStatsIndex",
"sensor_type": "clusterState",
"sensor_descr": "Cluster State",
"group": null,
"sensor_divisor": 1,
"sensor_multiplier": 1,
"sensor_current": 26190,
"sensor_limit": null,
"sensor_limit_warn": null,
"sensor_limit_low": null,
"sensor_limit_low_warn": 1,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": null,
"entPhysicalIndex_measured": null,
"sensor_prev": null,
"user_func": null,
"state_name": null
},
{
"sensor_deleted": 0,
"sensor_class": "count",
@ -233,30 +257,6 @@
"user_func": null,
"state_name": null
},
{
"sensor_deleted": 0,
"sensor_class": "state",
"poller_type": "snmp",
"sensor_oid": "fgHaSystemMode.0",
"sensor_index": "0",
"sensor_type": "clusterState",
"sensor_descr": "Cluster State",
"group": "HA",
"sensor_divisor": 1,
"sensor_multiplier": 1,
"sensor_current": 0,
"sensor_limit": null,
"sensor_limit_warn": null,
"sensor_limit_low": null,
"sensor_limit_low_warn": null,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": null,
"entPhysicalIndex_measured": null,
"sensor_prev": null,
"user_func": null,
"state_name": "clusterState"
},
{
"sensor_deleted": 0,
"sensor_class": "state",
@ -3309,10 +3309,10 @@
"sensor_deleted": 0,
"sensor_class": "state",
"poller_type": "snmp",
"sensor_oid": "fgHaStatsEntry",
"sensor_index": "0",
"sensor_type": "haSyncStatus",
"sensor_descr": "HA sync status",
"sensor_oid": ".1.3.6.1.4.1.12356.101.13.2.1.1.12.1",
"sensor_index": "fgHaStatsSyncStatus.1",
"sensor_type": "haSyncStatus 1",
"sensor_descr": "HA sync status sto-fw-01",
"group": "HA",
"sensor_divisor": 1,
"sensor_multiplier": 1,
@ -3323,28 +3323,14 @@
"sensor_limit_low_warn": null,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": "0",
"entPhysicalIndex": "1",
"entPhysicalIndex_measured": null,
"sensor_prev": null,
"user_func": null,
"state_name": "haSyncStatus"
"state_name": null
}
],
"state_indexes": [
{
"state_name": "clusterState",
"state_descr": "CRITICAL",
"state_draw_graph": 0,
"state_value": 0,
"state_generic_value": 2
},
{
"state_name": "clusterState",
"state_descr": "OK",
"state_draw_graph": 1,
"state_value": 1,
"state_generic_value": 0
},
{
"state_name": "fgHwSensors",
"state_descr": "OK",
@ -3386,32 +3372,35 @@
"state_draw_graph": 1,
"state_value": 2,
"state_generic_value": 0
},
{
"state_name": "haSyncStatus",
"state_descr": "Out Of Sync",
"state_draw_graph": 0,
"state_value": 0,
"state_generic_value": 2
},
{
"state_name": "haSyncStatus",
"state_descr": "In Sync",
"state_draw_graph": 1,
"state_value": 1,
"state_generic_value": 0
},
{
"state_name": "haSyncStatus",
"state_descr": "No Peer",
"state_draw_graph": 0,
"state_value": 2,
"state_generic_value": 1
}
]
},
"poller": {
"sensors": [
{
"sensor_deleted": 0,
"sensor_class": "count",
"poller_type": "snmp",
"sensor_oid": ".1.3.6.1.4.1.12356.101.13.2.1.1.1",
"sensor_index": "fgHaStatsIndex",
"sensor_type": "clusterState",
"sensor_descr": "Cluster State",
"group": null,
"sensor_divisor": 1,
"sensor_multiplier": 1,
"sensor_current": 1,
"sensor_limit": null,
"sensor_limit_warn": null,
"sensor_limit_low": null,
"sensor_limit_low_warn": 1,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": null,
"entPhysicalIndex_measured": null,
"sensor_prev": 26190,
"user_func": null,
"state_name": null
},
{
"sensor_deleted": 0,
"sensor_class": "count",
@ -3604,30 +3593,6 @@
"user_func": null,
"state_name": null
},
{
"sensor_deleted": 0,
"sensor_class": "state",
"poller_type": "snmp",
"sensor_oid": "fgHaSystemMode.0",
"sensor_index": "0",
"sensor_type": "clusterState",
"sensor_descr": "Cluster State",
"group": "HA",
"sensor_divisor": 1,
"sensor_multiplier": 1,
"sensor_current": 0,
"sensor_limit": null,
"sensor_limit_warn": null,
"sensor_limit_low": null,
"sensor_limit_low_warn": null,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": null,
"entPhysicalIndex_measured": null,
"sensor_prev": null,
"user_func": null,
"state_name": "clusterState"
},
{
"sensor_deleted": 0,
"sensor_class": "state",
@ -6680,42 +6645,28 @@
"sensor_deleted": 0,
"sensor_class": "state",
"poller_type": "snmp",
"sensor_oid": "fgHaStatsEntry",
"sensor_index": "0",
"sensor_type": "haSyncStatus",
"sensor_descr": "HA sync status",
"sensor_oid": ".1.3.6.1.4.1.12356.101.13.2.1.1.12.1",
"sensor_index": "fgHaStatsSyncStatus.1",
"sensor_type": "haSyncStatus 1",
"sensor_descr": "HA sync status sto-fw-01",
"group": "HA",
"sensor_divisor": 1,
"sensor_multiplier": 1,
"sensor_current": 2,
"sensor_current": 1,
"sensor_limit": null,
"sensor_limit_warn": null,
"sensor_limit_low": null,
"sensor_limit_low_warn": null,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": "0",
"entPhysicalIndex": "1",
"entPhysicalIndex_measured": null,
"sensor_prev": 1,
"sensor_prev": null,
"user_func": null,
"state_name": "haSyncStatus"
"state_name": null
}
],
"state_indexes": [
{
"state_name": "clusterState",
"state_descr": "CRITICAL",
"state_draw_graph": 0,
"state_value": 0,
"state_generic_value": 2
},
{
"state_name": "clusterState",
"state_descr": "OK",
"state_draw_graph": 1,
"state_value": 1,
"state_generic_value": 0
},
{
"state_name": "fgHwSensors",
"state_descr": "OK",
@ -6757,27 +6708,6 @@
"state_draw_graph": 1,
"state_value": 2,
"state_generic_value": 0
},
{
"state_name": "haSyncStatus",
"state_descr": "Out Of Sync",
"state_draw_graph": 0,
"state_value": 0,
"state_generic_value": 2
},
{
"state_name": "haSyncStatus",
"state_descr": "In Sync",
"state_draw_graph": 1,
"state_value": 1,
"state_generic_value": 0
},
{
"state_name": "haSyncStatus",
"state_descr": "No Peer",
"state_draw_graph": 0,
"state_value": 2,
"state_generic_value": 1
}
]
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff