Overview of snmp_func.inc

Public Variable Summary

Public variables are intended to be accessed by the code that imports this library.

Name Summary
last_snmp_error

Public Function Summary

Public functions are intended to be called by the code that imports this library.

Name Summary
snmp_get

Public Variable Details

last_snmp_error

top

Public Function Details

snmp_get

Named Parameters

oid
port
version

Code

function snmp_get(port, oid, version) {
  if (!defined_func("snmpv3_get"))
    return;

  if (!port || !oid)
    return;

  if (!version)
    version = get_kb_item("SNMP/prefered_version");

  if (version == 3) {
    if (!get_kb_item("SNMP/v3/timeout") && get_kb_item("SNMP/v3/working")) {
      v3_username = get_kb_item("SNMP/V3/username");
      v3_password = get_kb_item("SNMP/V3/password");
      v3_authalgo = get_kb_item("SNMP/V3/auth_algorithm");
      v3_privpass = get_kb_item("SNMP/V3/priv_password");
      v3_privalgo = get_kb_item("SNMP/V3/priv_algorithm");

      if (v3_username && v3_username != "") {
        if (!v3_privpass)
          v3_privalgo = NULL;

        ret = snmpv3_get(port: port, protocol: "udp", username: v3_username, oid: oid,
                         authpass: v3_password, authproto: v3_authalgo, privpass: v3_privpass,
                         privproto: v3_privalgo );

        if (ret[0] != 0 || "No Such Instance" >< ret[1]) {
          last_snmp_error = ret[1];
          if (ret[0] == "Timeout") {
            replace_kb_item(name: "SNMP/v3/timeout", value: TRUE);
            return;
          }
        }

        if (ret[0] == 0 && "No Such Instance" >!< ret[1])
          return ret[1];
      }
    }
  }

  if (version == 2) {
    if (!get_kb_item("SNMP/v2/timeout") && get_kb_item("SNMP/v2/working")) {
      community = get_kb_item("SNMP/V2/community");
      if (community && community != "") {
        ret = snmpv2c_get(port: port, oid: oid, protocol: "udp", community: community);
        if (ret[0] != 0 || "No Such Instance" >< ret[1]) {
          last_snmp_error = ret[1];
          if (ret[1] == "Timeout") {
            replace_kb_item(name: "SNMP/v2/timeout", value: TRUE);
            return;
          }
        }

        if (ret[0] == 0 && "No Such Instance" >!< ret[1])
          return ret[1];
      }
    }
  }

  if (version == 1) {
    if (!get_kb_item("SNMP/v1/timeout") && get_kb_item("SNMP/v1/working")) {
      community = get_kb_item("SNMP/community");
      if (community && community != "") {
        ret = snmpv1_get(port: port, oid: oid, protocol: "udp", community: community);
        if (ret[0] != 0) {
          last_snmp_error = ret[1];
          if (ret[1] == "Timeout") {
            replace_kb_item(name: "SNMP/v1/timeout", value: TRUE);
            return;
          }
        }
      if (ret[0] == 0)
          return ret[1];
      }
    }
  }

  return;
}



		
top