lordmilko / PrtgAPI

C#/PowerShell interface for PRTG Network Monitor
MIT License
305 stars 38 forks source link

How to add snmpdiskfree sensor for certain disks/targets #366

Closed aitchdot closed 7 months ago

aitchdot commented 1 year ago

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

lordmilko commented 1 year ago

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?

aitchdot commented 1 year ago

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?

lordmilko commented 1 year ago

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 commented 1 year ago

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?