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

[Feature Request] Specific Error Message for GetDynamicSensorParameters #140

Closed
JustinGrote opened this issue Mar 23, 2020 · 3 comments
Closed
Labels
enhancement Items that are on the todo list for incorporating into PrtgAPI in a future release

Comments

@JustinGrote
Copy link

internal static void ValidateAddSensorProgressResult(AddSensorProgress p, bool addFull)
{
if (p.TargetUrl.StartsWith("addsensorfailed"))
{
var parts = UrlUtilities.CrackUrl(p.TargetUrl);
var message = parts["errormsg"];
var action = addFull ? "add sensor" : "resolve sensor targets";
if (message != null)
{
message = message.Trim('\r', '\n');
//todo: does this work in other languages? Not sure how to replicate it
if (message.StartsWith("Incomplete connection settings"))
throw new PrtgRequestException("Failed to retrieve data from device; required credentials for sensor type may be missing. See PRTG UI for further details.");
throw new PrtgRequestException($"An exception occurred while trying to {action}: {message.EnsurePeriod()}");
}
throw new PrtgRequestException($"An unspecified error occurred while trying to {action}. Specified sensor type may not be valid on this device, or sensor query target parameters may be incorrect. Check the Device 'Host' is still valid or try adding sensor with the PRTG UI.");
}
if (addFull && p.Percent == -1)
throw new PrtgRequestException($"PRTG was unable to complete the request. The server responded with the following error: '{p.Error.Replace("<br/><ul><li>", " ").Replace("</li></ul><br/>", " ")}'.");
}

Add logic to parse out the div class "errormessage" and report it in the error so I can take action. In this example, I'll know the username/password for the sensor for VMware isn't correct and report that back appropriately or attempt a different credential.

<div id="main" data-title="Add Sensor Failed" data-contexthelpshow="false">
  <div id="failed" style="display:none">
    <p>Could not create the <a href='/help/vmware_host_hardware_status_soap_sensor.htm' target='_blank'><b>VMware Host Hardware Status (SOAP)</b></a> sensor on device <b><a  dependency="12187" deptype="select"  thisid="12002" class="devicemenu isnotpaused  isnotfavorite remoteprobe" style="background-image:url(/icons/devices/A_Server_1.png?svg)" id="12002" href="device.htm?id=12002">DIAUAIAESX02.field.ad.dncinc.com </a> (10.64.100.17)</b>.</p>
    <p><b style="color:red"><div class="errormessage">Cannot complete login due to an incorrect user name or password.</div></b></p>
@lordmilko lordmilko added the enhancement Items that are on the todo list for incorporating into PrtgAPI in a future release label Mar 24, 2020
lordmilko added a commit that referenced this issue Mar 24, 2020
…ors/resolving sensor targets/parameters when an error message is not included in the AddSensorProgress response (#140)
@lordmilko
Copy link
Owner

Hi @JustinGrote,

I have released a pre-release build of PrtgAPI 0.9.13 that includes this enhancement. Can you please follow the manual installation instructions and advise whether this works as expected?

For future enhancements please use the fancy Feature request/Idea template when creating an issue.

Unrelated, you may be interested to know that a previous commit for PrtgAPI 0.9.13 introduced a new -rt alias for -RawType on Get-SensorTarget / New-SensorParameters. I'm sure you will most agree this is a revolutionary feature :P

Regards,
lordmilko

@JustinGrote
Copy link
Author

@lordmilko thanks for the fast turnaround! Apologies on the Feature Request, I did a "new issue from line" in the code and it didn't present me with a template, maybe a Github limitation or something else that needs to be resolved.

I will be able to test later today when I get back to this item. Thanks.

@JustinGrote
Copy link
Author

@lordmilko works as expected! This is very helpful as I can now test if VMware credentials are correct without needing them saved outside of PRTG, since Paessler in their infinite wisdom didn't make them available to custom scripts while still letting windows and linux creds.

Here's some examples of messages I can now trap:

🏠(get-prtgclient).GetDynamicSensorParameters(11975,'esxserverhealthsensorextern')
MethodInvocationException: Exception calling "GetDynamicSensorParameters" with "2" argument(s): "An exception occurred while trying to resolve sensor targets: Please enter
 the VMware user and password in the device."
🏠(get-prtgclient).GetDynamicSensorParameters(12003,'esxserverhealthsensorextern')
MethodInvocationException: Exception calling "GetDynamicSensorParameters" with "2" argument(s): "An exception occurred while trying to resolve sensor targets: Cannot compl
ete login due to an incorrect user name or password."
🏠(get-prtgclient).GetDynamicSensorParameters(11975,'esxserverhealthsensorextern')
MethodInvocationException: Exception calling "GetDynamicSensorParameters" with "2" argument(s): "An exception occurred while trying to resolve sensor targets: Unable to co
nnect to the remote server."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Items that are on the todo list for incorporating into PrtgAPI in a future release
Projects
None yet
Development

No branches or pull requests

2 participants