You are here

Add SNMP Interfaces to monitor when adding a host through the API

4 posts / 0 new
Last post
Jeff Stockamp
jeff_2's picture
Add SNMP Interfaces to monitor when adding a host through the API

Is there any way to include the interfaces to monitor when I add a host through the API?  I've trying adding  "snmpinterfaces" with my eth devices I want to monitor, but that seems to fail.

Duncan Ferguson
dferguson's picture
To view the interfaces

To view the interfaces available where you know the ID of the host, you can use:

$ opsview_rest --username=admin --password=initial GET "config/host/4?cols=%2Bsnmpinterfaces" --pretty

Or, by hostname, you can use:

$ opsview_rest --username=admin --password=initial GET 'config/host?cols=%2Bsnmpinterfaces&json_filter={"name":"snmp-server"}' --pretty

As a quick test to update a host, I have redirected the output to a file, modified it, then uploaded it:

$ opsview_rest --username=admin --password=initial GET "config/host/4?cols=%2Bsnmpinterfaces" --pretty > snmpint
$ vi snmpint
$ opsview_rest --username=admin --password=initial PUT "config/host/4?cols=%2Bsnmpinterfaces" --content-file=snmpint --pretty

You should be able to create/update your hosts in a similar way, including the snmpinterfaces entries using the 'cols=+snmpinterfaces' URL parameter (the + is encoded as %2B in the above).

  Duncs

Jeff Stockamp
jeff_2's picture
Where does this go in the JSON config?

Thanks, I'm having a little trouble figuring out where this goes in the JSON object that's I'm passing to the API?  I'm not using the opsview_rest command line, I'm using the opsview python library.  I've tried adding a key for "snmpinterfaces" but that doesn't seem to be working.

For a little more background ... what I'm trying to do is query an AWS ELB to find instances that have been created and/or removed due to autoscaling and I'm adding/removing them from opsview through a service check.  I've got everything working except for SNMP interfaces.

Duncan Ferguson
dferguson's picture
If you run a configuration

If you run a configuration query against a device you already have set up with interfaces, you should see it is set up similar to:

.....................
    snmp_max_msg_size             => 0,
    snmp_port                     => 161,
    snmp_version                  => "2c",
    snmpinterfaces                => [
                                       {
                                         active              => 0,
                                         discards_critical   => 15,
                                         discards_warning    => undef,
                                         duplicatename       => 0,
                                         errors_critical     => 10,
                                         errors_warning      => undef,
                                         indexid             => 0,
                                         interfacename       => "",
                                         throughput_critical => "0:50%",
                                         throughput_warning  => undef,
                                       },
                                       {
                                         active              => 1,
                                         discards_critical   => "",
                                         discards_warning    => "",
                                         duplicatename       => 0,
                                         errors_critical     => "",
                                         errors_warning      => "",
                                         indexid             => 0,
                                         interfacename       => "eth0",
                                         throughput_critical => "",
                                         throughput_warning  => "",
                                       },
                                     ],
    snmpv3_authprotocol           => undef,
    snmpv3_privprotocol           => undef,
...................

If necessary, instead of manually working out what all the details are for interfaces, you can run a query over the REST API and use the details from the 'interfaces' section to populate the values for the host

$ opsview_rest --username=admin --password=initial POST "queryhost?ip=qa-snmp.nova.opsview.com&snmp_version=2c&snmp_community=public" --pretty
{
  interfaces => [
    {
      discards_critical => 15,
      discards_warning => "",
      errors_critical => 10,
      errors_warning => "",
      extra_info => "alias:'' speed:'' link:'' status:''",
      id => 0,
      ifAlias => undef,
      ifDescr => "",
      ifLink => undef,
      ifSpeed => undef,
      ifSpeedRaw => undef,
      ifStatus => undef,
      interfacename => "",
      throughput_critical => "0:50%",
      throughput_warning => "",
    },
.....................

See https://knowledge.opsview.com/articles/opsview-monitor-510/512-rest-api-queryhost.html for more details.

  Duncs