Fortinet white logo
Fortinet white logo

User Guide

26.1.0

SNMP extension

SNMP extension

If you want to build and test custom plugins which send SNMP queries, you should add variables to the metadata for SNMP access to the target device.

def snmp_get(self, hostname: str, oid: str) -> int | str | None

Get a single value for oid on the SNMP device that is integrated into FortiMonitor.

  • hostname: hostname of target device. you can use the hostname passed to get_data() function

  • oid: object identifier to query

def get_data(self, textkey, option, instance_id, hostname,
             device_type, device_sub_type, tags, attributes):
    value = self.snmp_get(hostname, "1.3.6.1.4.1.12356.101.4.1.4.0")
    return value

def snmp_get_multi(self, hostname: str, oids: list[str]) -> dict[str, int | str]

Get multiple value for a list of oids on the SNMP device that is integrated into FortiMonitor.

  • hostname: hostname of target device. you can use the hostname passed to get_data() function

  • oids: list of object identifiers to query

def get_data(self, textkey, option, instance_id, hostname,
             device_type, device_sub_type, tags, attributes):
    result = self.snmp_get_multi(
        hostname,
        ["1.3.6.1.4.1.12356.101.4.1.4.0", "1.3.6.1.4.1.12356.101.4.1.8.0"]
    )
    return sum(v for v in result.values() if type(v) == int)

def snmp_walk(self, hostname: str, oid: str) -> dict[str, int | str]

Get multiple value for oid and the subtree of oid on the SNMP device that is integrated into FortiMonitor.

  • hostname: hostname of target device. you can use the hostname passed to get_data() function

  • oid: object identifier to walk

def get_data(self, textkey, option, instance_id, hostname,
             device_type, device_sub_type, tags, attributes):
    result = self.snmp_walk(hostname, "1.3.6.1.4.1.12356.101.4.1")
    return sum(v for v in result.values() if type(v) == int)

SNMP extension

SNMP extension

If you want to build and test custom plugins which send SNMP queries, you should add variables to the metadata for SNMP access to the target device.

def snmp_get(self, hostname: str, oid: str) -> int | str | None

Get a single value for oid on the SNMP device that is integrated into FortiMonitor.

  • hostname: hostname of target device. you can use the hostname passed to get_data() function

  • oid: object identifier to query

def get_data(self, textkey, option, instance_id, hostname,
             device_type, device_sub_type, tags, attributes):
    value = self.snmp_get(hostname, "1.3.6.1.4.1.12356.101.4.1.4.0")
    return value

def snmp_get_multi(self, hostname: str, oids: list[str]) -> dict[str, int | str]

Get multiple value for a list of oids on the SNMP device that is integrated into FortiMonitor.

  • hostname: hostname of target device. you can use the hostname passed to get_data() function

  • oids: list of object identifiers to query

def get_data(self, textkey, option, instance_id, hostname,
             device_type, device_sub_type, tags, attributes):
    result = self.snmp_get_multi(
        hostname,
        ["1.3.6.1.4.1.12356.101.4.1.4.0", "1.3.6.1.4.1.12356.101.4.1.8.0"]
    )
    return sum(v for v in result.values() if type(v) == int)

def snmp_walk(self, hostname: str, oid: str) -> dict[str, int | str]

Get multiple value for oid and the subtree of oid on the SNMP device that is integrated into FortiMonitor.

  • hostname: hostname of target device. you can use the hostname passed to get_data() function

  • oid: object identifier to walk

def get_data(self, textkey, option, instance_id, hostname,
             device_type, device_sub_type, tags, attributes):
    result = self.snmp_walk(hostname, "1.3.6.1.4.1.12356.101.4.1")
    return sum(v for v in result.values() if type(v) == int)