To get alerted for an exception in a custom plugin, include the attributes ['status'] = 0 and ['msg']=str(e) under Exception.
What do the attributes denote?
1. status: Denotes the availability of the monitor.
The value can either be:
- 1, which means the status is Up and metrics are collected successfully, or
- 0, indicating the status is Down and metrics cannot be collected due to a script error or failure to connect to the remote server or API.
2. msg: These are messages for the monitor when in Down status.
Both of the above are
reserved keys, and you can add the above attributes in the Exception section.
This would change the monitor status to Down if there is an error in the plugin, and ensure that the exception captured in the 'msg' keyword would be shown as the reason for the Down status.
except Exception as e:
data["status"]=0
data["msg"]=str(e)
catch
{
$Script:Status = 0
$Script:msg = $_.Exception.Message
}
Tip: Add this in your plugin scripts for faster troubleshooting.