Support Questions
Find answers, ask questions, and share your expertise

Custom AMBARI alert fail

Custom AMBARI alert fail

New Contributor

Hello,

I have a problem with the custom script we have created the script in python which controls FreeIPA and Kerberos and resides on kerberos nodes, that is outside of AMBARI.

# cat alert_kerberos.py
#! / usr / bin / env python

import subprocess
import os
import sys

def command_alert ():
ipa = subprocess.check_output (["ipactl", "status"])
if ipa.find ("STOPPED") <0:
result = "OK"
other:
result = "CRITICAL"
return sys.exit (result)

 

if __name__ == "__main__":
command_alert ()


Finally, on the MANAGER node (where the ambari server is installed) the script to be added to the alerts has been created which recalls the one previously created


# cat alert_kerberos_ambari.py
#! / usr / bin / env python

import subprocess

subprocess.call ("ssh <kerberos_hosts> python alert_kerberos.py", shell = True)

Come out has OK or CRITICAL as requested by Ambari.
The json it is loaded with is this:


# cat alert_kerberos_ambari.py
#! / usr / bin / env python

 

import subprocess

 

subprocess.call ("ssh <kerberos_hosts> python alert_kerberos.py", shell = True)
[root @ tst-manager1 ~] # cat alert_kerberos_ambari.json
{
"AlertDefinition":
{
"service_name": "AMBARI",
"scope": "HOST",
"activated": true,
"description": "Custom script to verify FreeIPA",
"name": "freeipa_up",
"component_name": "AMBARI_AGENT",
"interval": 1,
"label": "FreeIpa monitoring process",
"source": {
"path": "alert_kerberos_ambari.py",
"type": "SCRIPT",
"parameters": [
{
"display_name": "Service inactive",
"name": "service.down",
"value": 300.0,
"threshold": "CRITICAL",
"unit": "seconds",
"type": "NUMERIC",
"description": "Checking the FreeIpa service"
}
]
}
}
}

The tried with to load it on Ambari but, once loaded, it does not perform what it should and marks the whole list of hosts in an unknown state.

we uploaded it to Ambari with this command

curl -u <user>: <password> -i -k -H 'X-Requested-By: ambari' -X POST -d @ alert_kerberos_ambari.json https://<AMBARI_HOST>:443/ api / v1 / clusters / <cluser_name> / alert_definitions

and we see it on Ambari, but it doesn't work and always remains in Unknown state with the wording


'NoneType' object has no attribute 'modules'.

Any ideas?

Thanks
BR