PrtgAPI icon indicating copy to clipboard operation
PrtgAPI copied to clipboard

How to add snmpdiskfree sensor for certain disks/targets

Open aitchdot opened this issue 2 years ago • 4 comments

What's going on?

I'm trying to add snmpdiskfree sensor but only for certain disks with channel properties already set.

E.g.

    public static bool AddSensor(PrtgClient client, Device d)
	{
	       var pingParams = client.GetDynamicSensorParameters(d, "snmpdiskfree");
               // Only Targets/Disks Where(n => !n.Name.Contains("/run");
               var sensors = client.AddSensor(d, pingParams);
		foreach (var sensor in sensors)
		{
                        var channels = sensors.SelectMany(s => client.GetChannels(sensor, "Free Space"));
			foreach (var channel in channels)
			{
                            client.SetChannelProperty(channel, ChannelProperty.LowerErrorLimit, 5);
                            client.SetChannelProperty(channel, ChannelProperty.LowerWarningLimit, 10);
                        }
                }
    }

Due Dilligance

  • [X] It wasn't covered by the wiki, I swear!
  • [X] I have tried doing some basic research on this issue but haven't been able to come up with anything. Please help!

aitchdot avatar Nov 07 '23 10:11 aitchdot

I don't understand what you're trying to do, and I don't see a question here. Is there a specific issue with PrtgAPI you are having?

lordmilko avatar Nov 08 '23 02:11 lordmilko

There is actually two problems in my post. I'm unable to add snmpdiskfree sensors with a specific disk, it will always only add the first disk. I'm, trying to add / and /boot as example

In the UI:

image

Second, if i try to use the example for setting channel thresholds, SelectMany will return a type, I'm unable to use in the SetChannelProperty after.

How do i setup snmpdiskfreesensor for multiple disks or targets i guess and how do i set the adequate channelproperties / thresholds after?

aitchdot avatar Nov 08 '23 14:11 aitchdot

You need to set the disks you want to create. See Targets for more info. Your debugger should help show you the name of the property on the DynamicSensorParameters that you need to set the targets on

lordmilko avatar Nov 08 '23 22:11 lordmilko

Second, if i try to use the example for setting channel thresholds, SelectMany will return a type, I'm unable to use in the SetChannelProperty after.

Are you able to advise what you mean exactly? SelectMany should return an IEnumerable<Channel>, which you're then enumerating over and passing each Channel to SetChannelProperty. Are you getting some type of error or are you saying that the method executes but nothing happens in PRTG?

lordmilko avatar Nov 08 '23 22:11 lordmilko