Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNMP Value Retrieval #1675

Open
1 task done
wglenn01 opened this issue May 23, 2022 · 62 comments · May be fixed by #4717
Open
1 task done

SNMP Value Retrieval #1675

wglenn01 opened this issue May 23, 2022 · 62 comments · May be fixed by #4717
Labels
area:monitor Everything related to monitors feature-request Request for new features to be added

Comments

@wglenn01
Copy link

⚠️ Please verify that this feature request has NOT been suggested before.

  • I checked and didn't find similar feature request

🏷️ Feature Request Type

New Monitor

🔖 Feature description

I would love to be able to put in custom SNMP OID's per device to monitor the value of that OID with each update and display them in the table, would be SO helpful.

✔️ Solution

Add SNMP monitoring for custom OID's per device.

❓ Alternatives

No response

📝 Additional Context

No response

@wglenn01 wglenn01 added the feature-request Request for new features to be added label May 23, 2022
@Computroniks

This comment was marked as resolved.

@louislam
Copy link
Owner

As long as it is about uptime and downtime, it could be a monitor type in Uptime Kuma.

But honestly, I probably won't implement this, as I don't use and I don't know what is SNMP.

@Computroniks
Copy link
Contributor

Computroniks commented May 31, 2022

SNMP is a protocol that is used to get metrics such as CPU and network utilization from devices, especially networking devices such as switches and routers. Here is a Wikipedia article with some more info: https://en.wikipedia.org/wiki/Simple_Network_Management_Protocol

@Lucienest

This comment was marked as spam.

@AlmightyJojo
Copy link

I have yet to explore this project but am interested. However the first thing I did was look if SNMP was included. Its is very useful. But does take time to get configured and learn device OIDs.

I currently use Syncro RMM but have been looking for alternative solutions. The way Syncro does it is their main Windows based monitor agent installed at customer's local site gets designated as a SNMPv2 monitoring agent. It then does over LANs to query SNMP OIDs then reports back cloud via the designated monitoring agent.

Here's maybe some inspiration to consider adding SNMP. Lots good monitoring and info.
Pics of Poweredge IDRAC8, N2024 2x switch stack, and APC UPS.

https://i.imgur.com/nSsMz7P.png
https://i.imgur.com/SnBbQGT.png
https://i.imgur.com/2H9l6Kx.png

@phinnay
Copy link

phinnay commented Mar 7, 2023

Bumping this as it'd be very useful for how I am using UptimeKuma.

@louislam Respectfully disagree that this is outside the scope of the application - SNMP is a way to query for data, the logic as to what that data does in UptimeKuma would be where ya'd want to be careful. I agree getting into the weeds with complicated checks is better suited to other products, (Icinga, Nagios, etc...) however querying SNMP for simple values like toner level or if a switch port is up / down is no more out of scope than the existing SQL monitoring that operates the same way.

I'd propose to literally copy how the SQL monitor works but for SNMP. Simply providing a red/yellow/green status and a graph over time of the queried value would be of tremendous value, even for home users.

Thanks again for a wonderful product and the time that has gone into it. I wish I was better with code to help implement this feature myself.

@mattv8
Copy link

mattv8 commented Apr 19, 2023

The perfect use-case for me would be to monitor the status of our security cameras- whether they are recording or not. While I can simply set up a ping-test for all of our cameras, this doesn't actually indicate to me that they are successfully recording to the NVR. We use a Lorex NVR system that has an SNMP interface with a query-able status for each camera.

@Lucienest

This comment was marked as spam.

@wglenn01

This comment was marked as spam.

@GH-HNZ
Copy link

GH-HNZ commented May 3, 2023

adding basic SNMP protocol support with the possibility for custom OIDs would be good enough, later you can think of adding feats like OID discovery, and perhaps merging or grouping the SNMP checks into a single node or linking to an existing ICMP monitor, shouldn't be that complicated in my opinion.

@charettemtb

This comment was marked as spam.

@Lucienest

This comment was marked as spam.

@dev-Blaze

This comment was marked as spam.

@chakflying

This comment was marked as resolved.

@Lucienest

This comment was marked as spam.

@CommanderStorm

This comment was marked as resolved.

@vladaurosh
Copy link

Given that this Project is open source, you could also provide a Pull Request (with extensive screenshots, as I would not know where to get a device with SNMP) 😉

Cheap Mikrotik switch (40$ new) should get you SNMP.
image

@phinnay
Copy link

phinnay commented Jul 6, 2023

Given that this Project is open source, you could also provide a Pull Request (with extensive screenshots, as I would not know where to get a device with SNMP) 😉

I just noticed this was getting some activity!

SO many devices support SNMP, if you have a network printer, managed switch... anything there's a high chance of it supporting SNMP.

Without purchasing anything - Both windows and linux support SNMP reporting out the box. You can enable it in your OS and then query well known OIDs to pull values from your computer

Example:
https://www.sysadmin.md/snmp-most-useful-linux-oids.html

Hope that helps!!

@Slamkryp

This comment was marked as spam.

@stacksjb
Copy link

stacksjb commented Aug 3, 2023

One extrememly useful area for this would be for monitoring uptime of connected devices, as opposed to devices directly.

For example, I have about 14 IoT devices connected wirelessly. Monitoring them seperately is a pain, and if my AP goes down, they all fire.

However, if I monitor my Wifi AP directly via SNMP, I can monitor them from the list of connected devices.

IMHO this kind of basic monitoring is exactly what should be supported.

@CommanderStorm
Copy link
Collaborator

exactly what should be supported

Given that monitors which come from the community work better (because the dev providing the implementation understands what SNMP is and has a device to test this on), this would be how to get this feature.
=> A reasonable PR implementing this feature is likely to get merged

See this PR for a somewhat similar monitor: #3178
Here is our contribution guide: https://github.com/louislam/uptime-kuma/blob/master/CONTRIBUTING.md

@markosole
Copy link

I am happy to see interest in this, well the same thing I am looking for as well. I am using UptimeKuma for 50+ different services (what's supported) and last piece is (to fill the gaps) SNMP for devices and for a simple metrics.
I will loook into extending it myself and will share some info. Fingers drossed!

@NEBELWAENDE
Copy link

Maybe this might be a light path or bridge to get over - i have seen, that "uptime kuma", which i like very much, fires up several ping commands (i use Ping Monitors in Uptime Kuma) as one can see on the console/syslog in the docker image i run. I am wondering if someone could figure out if the net-snmp commands snmpwalk and snmpget resp. snmptable command could be helpfull to get certain snmp values from e.g. printers routers and switches. just a thought that it could be a way ...

@phinnay
Copy link

phinnay commented Sep 20, 2023

Maybe this might be a light path or bridge to get over - i have seen, that "uptime kuma", which i like very much, fires up several ping commands (i use Ping Monitors in Uptime Kuma) as one can see on the console/syslog in the docker image i run. I am wondering if someone could figure out if the net-snmp commands snmpwalk and snmpget resp. snmptable command could be helpfull to get certain snmp values from e.g. printers routers and switches. just a thought that it could be a way ...

that would make a lot of sense!

To someone who knows coding this PR could be a literal copy/paste from the SQL monitor but switch out the heavy lifting by passing values to net-snmp

Love the product, hope this gets traction!

@CommanderStorm

This comment was marked as resolved.

Repository owner deleted a comment from NEBELWAENDE Feb 2, 2024
Repository owner deleted a comment from NEBELWAENDE Feb 2, 2024
Repository owner deleted a comment from NEBELWAENDE Feb 2, 2024
@CommanderStorm

This comment was marked as resolved.

@AlmightyJojo

This comment has been minimized.

@Slamkryp

This comment was marked as duplicate.

@CommanderStorm
Copy link
Collaborator

@Slamkryp I think my comment has moved so far to the top that reposting is beneficial

No PR has been raised with support for this. @ NEBELWAENDE has posted some code which would need to be fittend into our monitoring-type's and tested that it works. An example for a PR implementing a monitoring-type is #3178

Our contribution guide is available here https://github.com/louislam/uptime-kuma/blob/master/CONTRIBUTING.md

@Densen2002

This comment was marked as duplicate.

@Densen2002
Copy link

I found a way to make friends - Uptime Kuma with Mirkotik without SNMP protocol support.

The task is to monitor in Uptime Kuma the status of Mikrotik and the map of its TheDude networks

  1. in Uptime Kuma we should create a New Monitor, select the PUSH type, and get a unique push URL, define the waiting interval, for example, 60 seconds, and the “polarity” (Flip the status upside down. If the service is reachable, it is DOWN ).

for example http://192.168.80.87:3001/api/push/AdSiDEOE6s?status=up&msg=OK&ping=

  1. In Mikrotik, we should create a tool that will “peck” push URL, informing us in Uptime Kuma about what we have in mind - whether it works or does not work.
    /tool fetch url=http://192.168.80.87:3001/api/push/AdSiDEOE6s?status=up&msg=OK&ping=" keep-result=no

  2. in Uptime Kuma we see that Mikrotik is alive and what we have in mind - whether it works or not.

You can create as many of these Monitors as you like.

The trick is that using the method described above, you can “upload” various events and service states, for example, SNMP OIDs change or Network Watch Alerts, from the TheDude network map to the Uptime Kuma server. And so on.

@camdenyoung
Copy link

I would strongly support and encourage integration of SNMP. Its a fundamental and industry standard of monitoring network equipment.

To give some realworld use, for our temporary deployments we monitor not just that a switch is connected (simple ping response), but with SNMP, is an individual port up or down, has it negocitated at the correct link speed, is it full or half duplex. Any of these could alert to a potential uptime problem about to occur.

We also deploy many microwave links, so for monitoring purposes, we dont just want to know the link is up/connected, but what is the signal strenth (RSSI), what is the throughput, etc. This is all simply collected via SNMP. Just because you can get a ping response from the microwave link at the other end, doesnt mean the link isnt about to fail, or is running at an acceptable speed.

We currently use Nagios for our monitoring, which does the job, but its an awful system to actually setup and maintain, and just isnt user friendly for the rest of our less technical team compared to the fantastic interface you've created with Uptime Kuma.

Don't waste time on intergrating OID library's for individual products, leave that to user to enter the values they need to retrieve. Most quality equipment has this documented anyway and/or there are hundreds of products already out there that let you scan a device to find the OID you require anyway.

@Slamkryp

This comment was marked as spam.

@CommanderStorm

This comment was marked as resolved.

@owlysk
Copy link

owlysk commented Apr 17, 2024

Hello guys,
I decided to try implement this monitor.

I think it should be like this:
You will set up IP address of device, SNMP version number, community string for SNMPv1 & SNMPv2c and OID you want to check. One OID per monitor. Then I think you should set control value and condition. For example, I want to check, if OID value is greater than 30% (30% is my control value).
Conditions will be:

  • > - check integer
  • >= - check integer
  • =< - check integer
  • <= - check integer
  • == - check integer & string
  • contains - check if string is in OID value

Monitoring will check OID value against condition. If OID value is > than control value = UP. Otherwise it returns DOWN. If device will be offline, returns DOWN.

Is that behaviour correct?


For now I won't implement SNMPv3.

@camdenyoung
Copy link

Hi @owlysk, yes that's the fundamental concept, but keep in mind an OID from a network appliance can return a string or integer, depending on what element is being monitored.

Going back to my microwave link example from earlier, if I check the state of an ethernet port, the OID response would be the string of 'up' or 'down', but if I check the RSSI (signal strength) that would return a value anywhere between -128 (dBm) to -20 (dBm).

And thanks for looking into this! Really appreciate it. I wouldn't rush to implement SNMP v3. Yes its the newer (more secure protocol because it has auth) but I honestly would hazard a guess most implementations are still on v2, unless crossing wan connections.

@chakflying
Copy link
Collaborator

chakflying commented Apr 18, 2024

Sounds pretty good, but just in case you didn't know, you should take a look at how the json-query monitor works.

Ideally in the long term, we would want all value comparisons to work with the jsonata syntax, and reuse the database fields for better compatibility (see #3919). I don't think it's worth implementing custom value comparison functionality just for this monitor.

@owlysk
Copy link

owlysk commented Apr 21, 2024

@camdenyoung can you please provide output from snmpwalk for signal strength? I want to know what response look like.

@chakflying thank you, I didn't know that. I'll take a look.

@mattv8 mattv8 linked a pull request Apr 27, 2024 that will close this issue
7 tasks
@mattv8
Copy link

mattv8 commented Apr 27, 2024

Hey @owlysk I've started working on implementing this feature. It's nowhere near complete, but I'm dropping my work thus far into PR #4717. I've laid the framework for your control_value logic. I'll continue to work on this next week (I'm assuming I won't have time over the weekend but ya never know).

@mattv8
Copy link

mattv8 commented Apr 29, 2024

@owlysk I'm wondering if you'd be able to take a look. I'm basically stuck with a strange timeout issue. See my PR, specifically, #issuecomment-2083823715

@camdenyoung
Copy link

Apologies @owlysk, I've been away the last week. I'm back in the office now if you still need me to send through an snmpwalk?

@camdenyoung
Copy link

camdenyoung commented Apr 30, 2024

@owlysk @mattv8 below is the result for RSSI (signal strength) from a Siklu EH-710 microwave link as an example

snmpget -v 2c -c public 10.27.2.82 .1.3.6.1.4.1.31926.2.1.1.19.1
SNMPv2-SMI::enterprises.31926.2.1.1.19.1 = INTEGER: -26

Setting thresholds is where it matters with sensors such as these. A link that is powered up, but has no wireless connection will return a value of -128 (dBm).

A connection anywhere between -20 (dBm) through -55 (dBm) is generally a healthy link, but is relative to what the physical distance the links are connecting across. So, with the above example unit that is reporting a -26 RSSI, I might set a warning threshold at -30 and then a critical if it equals or passes -40 for example.

@mattv8
Copy link

mattv8 commented Apr 30, 2024

@camdenyoung I'm essentially implementing @owlysk's suggested logic for checking SNMP:

> - check integer
>= - check integer
=< - check integer
<= - check integer
== - check integer & string
contains - check if string is in OID value

However, one potential issue I foresee is that often times OID's will report values in binary, or OctetString (more on that here). So we need to have logic in place to handle those situations.

In my PR I was originally going to use snmp-native, but I am switching to net-snmp because has SNMP walking. As I work on this feature, I wrote an SNMP walking script, which I used to try to parse my Cisco SG-300 switch. I let the walk run for 30 minutes or so and it reported back 211,468 unique OID's parsable in Cisco's default RO library... So I think implementing an SNMP walk for this feature is impractical. Which is frustrating because unless you already know the OID you're wanting to monitor, there isn't some central directory to easily look up, for example, CPU usage on my Cisco switch...

Posting my SNMP walking script for the record:

Click to view code
const fs = require('fs');
const snmp = require('net-snmp');

// Configuration
const monitor = {
  ipAddress: 'changeme',
  port: '161',
  communityString: 'public',
  snmpVersion: '2c',
  rootOid: '1.3.6.1',// This is pretty high level
};

// SNMP options
const options = {
  port: monitor.port,
  retries: 1,
  timeout: 5000,
  version: snmp.Version2c,
};

// Create SNMP session
const session = snmp.createSession(monitor.ipAddress, monitor.communityString, options);

// Create writable stream for CSV
const csvStream = fs.createWriteStream('snmp_data.csv');

// Function to handle SNMP walk feed callback
function feedCb(varbinds) {
  for (const varbind of varbinds) {
      if (!snmp.isVarbindError(varbind) && varbind.value !== null && varbind.value !== undefined) {
          console.log(`OID: ${varbind.oid}, Type: ${findType(varbind.type)}, Value: ${varbind.value}`);
          const csvRow = `${varbind.oid},${findType(varbind.type)},${varbind.value}\n`;
          csvStream.write(csvRow);
      }
  }
}

// Function to handle SNMP walk done callback
function doneCb(error) {
  if (error) {
      console.error(error.toString());
  } else {
      console.log('SNMP walk completed.');
  }
}

// Start SNMP walk from the specified OID
session.walk(monitor.rootOid, 20, feedCb, doneCb);

// Function to find the corresponding type name for a given value
function findType(value) {
  const typeName = Object.entries(snmp.ObjectType).find(([key, val]) => val === value);
  return typeName ? typeName[0] : 'Unknown';
}

@camdenyoung
Copy link

As you've just discovered, I wouldn't worry about implementing any OID scanning functionality. There are thousands of tools out there that the user can utilise to find the right OID for the sensor / status to be monitored. Leave it to the user to know what OID to enter, then only functionality required from the uptime kuma perspective is the logic behind the alert. Is the value true or false, or is the threshold met or exceeded, etc.

On a side note though, it might be worth having a look over librenms GitHub. This is a much higher level (and as a result, significantly more complicated) monitoring solution, but it might help explain how they have implemented the scanning functionality as well as the monitoring side.

@mattv8
Copy link

mattv8 commented Apr 30, 2024

Thanks for the tip to librenms, I'll take a look. I'll also continue working on the PR tomorrow morning, but I was able to get basic functionality working at least, so I can sleep tonight...

@mattv8
Copy link

mattv8 commented Apr 30, 2024

Alright I finished this monitor and have requested review of the PR. For now, I'm not going to implement any sort of OID discovery-- it's just too complicated. I'm going to assume people know the OID they want to monitor already and can paste it in.

If anyone wants to check out this feature, you can clone my PR #4717 and test for yourself. It's working well so far in my dev environment.
The PR can be tested via

docker run --rm -it -p 3000:3000 -p 3001:3001 --pull always -e 'UPTIME_KUMA_GH_REPO=mattv8:snmp-monitor' louislam/uptime-kuma:pr-test2

@owlysk
Copy link

owlysk commented May 2, 2024

@camdenyoung Thank you for snmpwalk result. @mattv8 was quicker in implementation, than me :)

@mattv8 I'm testing your PR but I always get error - Request timed out. I'm using SNMPv1.

@mattv8
Copy link

mattv8 commented May 2, 2024

Hey @owlysk I got lucky and had some spare time. 🙂

I'm currently working through the error you're seeing. There is an issue with how my code is parsing strings: SNMP Error: toString() radix argument must be between 2 and 36. Working on this now, should have resolution in an hour or so.

@mattv8

This comment was marked as outdated.

@mattv8
Copy link

mattv8 commented May 2, 2024

@owlysk I have committed my code fixing the issue you were encountering. Please re-pull the updated docker image with my latest commits.

If you're still seeing Request timed out it is likely that you need to turn on the SNMP service on your SNMP enabled device. Verify you have configured a community string-- this is essentially the password for your SNMP queries.

FWIW I'm testing on my Cisco SG-300 switch. I had to go into the device's web interface and turn on the SNMP server, and configure a community string as well as a "view" which turns on a specific set of OID's.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:monitor Everything related to monitors feature-request Request for new features to be added
Projects
None yet
Development

Successfully merging a pull request may close this issue.