lordmilko / PrtgAPI

C#/PowerShell interface for PRTG Network Monitor
MIT License
301 stars 37 forks source link

How to Define Channels for Business Process Sensors? #89

Closed ninjo99 closed 5 years ago

ninjo99 commented 5 years ago

Hello,

I'm trying to use the API with C# to add Business Process sensors but I'm not finding a way to define channels for this sensor type. I tried using the Dynamic Parameters method for this but there is no name associated with the channel where object IDs are supposed to be assigned when creating the sensor manually in the PRTG web interface. I also reviewed the Sensor Factories documentation since this is a type of Sensor Factory sensors but couldn't find a way to make it work for the Business Process sensor but perhaps I am missing something... Is it possible to work with this sensor type using the API?

lordmilko commented 5 years ago

Hi @ninjo99,

Using Fiddler I was able to see that PRTG JSON encodes the information specified in the Business Process sensor under the "businessprocessdefinitions_" property

[{"objects":[2079],"warningthreshhold":75,"errorthreshhold":50,"channelname":"potato"},{"objects":[],"warningthreshhold":75,"errorthreshhold":50,"channelname":"tomato"}]

I have also discovered however that in the latest version of PrtgAPI, it is not actually possible to retrieve DynamicSensorParameters for Business Process sensors, as this sensor type does not actually get included in the list of sensor types supported by a device (returned by the request to api/sensortypes.json?id=<device>.

Unless I can find some way of making sensortypes.json include the businessprocess sensor type I may have to include native support for creating business process sensors in the next version of PrtgAPI. Until then, users using PrtgAPI 0.9.6 and above can likely only create business process sensors using a set of custom sensor parameters. Users using PrtgAPI 0.9.5 and lower (which sounds like your scenario) can continue to take advantage of the fact that PrtgAPI does not include these additional validations.

Are you able to advise whether the information about the businessprocessdefinitions property specified above provides the information you need?

Regards, lordmilko

lordmilko commented 5 years ago

After retesting this evening it appears there is no issue retrieving dynamic sensor parameters for business process sensors using PrtgAPI 0.9.6+; I believe I may been testing on an older version of PRTG that did not actually include this sensor type :P

ninjo99 commented 5 years ago

Hi @lordmilko,

I am using PrtgAPI 0.9.7 so it sounds like I should be able to use the dynamic sensor parameters for the business process sensors; however, I am a bit unclear on how to make that work. I can successfully assign the "channelname" parameter with the below code:

var parameters = session.GetDynamicSensorParameters(device, "businessprocess"); parameters.Name = "Business Process Sensor"; parameters["channelname"] = "Channel 1"; parameters["objects"] = "16658"; var sensors = session.AddSensor(device, parameters);

The "objects" parameter causes an exception though stating "Parameter with name 'objects' does not exist. Are all of these channel parameters supposed to be defined under the "businessprocessdefintions_" property?

Thanks,

ninjo99

lordmilko commented 5 years ago

Hi @ninjo99,

Correct - you need to define a JSON string and assign it to the businessprocessdefinitions_ property

parameters["businessprocessdefinitions"] = "[{\"objects\":[2079],\"warningthreshhold\":75,\"errorthreshhold\":50,\"channelname\":\"potato\"},{\"objects\":[],\"warningthreshhold\":75,\"errorthreshhold\":50,\"channelname\":\"tomato\"}]"

Regards, lordmilko