Support Questions

Find answers, ask questions, and share your expertise

how to test custom ambari alert

Expert Contributor

I uset hdp 2.4 and ambari 2.2.1.1

I had custom an ambari alert and test on my test servers.

But when I copy it on mysql product environment, one server seems every thing is ok,and the other is show me :

'NoneType' object has no attribute 'modules' 

So, I try to the monitor script writen in pytthon.

When I run python monitor.py, it shows ok,but on the ambari-agent,it still wrong.

So is there a way to test the script and debug the monitor script??

1 ACCEPTED SOLUTION

Expert Contributor

What I don't clear is why on one server show me

'NoneType' object has no attribute 'modules'

,but the other is ok

I try to restart the ambari-agent,It show me ok

So terrible.

resloved.

View solution in original post

10 REPLIES 10

Super Mentor

@darkz yu

The error that you posted indicates some issue with your "monitor.py" python script.

'NoneType'object has no attribute 'modules'

.

Please try running that script manually to see if it works or causes the same error? Please make sure that it uses the PYTHONPATH that your ambari agent is using.

# python monitor.py

.

For example the pythonpath i use as following:

export PYTHONPATH=/usr/lib/python2.6/site-packages:/usr/lib/python2.6/site-packages/ambari_commons:/usr/lib/python2.6/site-packages:/usr/lib/python2.6/site-packages:/usr/lib/python2.6/site-packages/ambari_commons:/usr/lib/python2.6/site-packages::/usr/lib/python2.6/site-packages:/usr/lib/python2.6/site-packages/ambari_agent:/usr/lib/python2.6/site-packages

.

Super Mentor

@darkz yu

Also will it be possible if you can share your monitor.py script.

Super Mentor

@darkz yu

Where exactly are you putting your custom alert script? Is it the following location?

/var/lib/ambari-server/resources/host_scripts

.

I have written a similar article on this customization: https://community.hortonworks.com/articles/38149/how-to-create-and-register-custom-ambari-alerts.htm...

Above link will give some idea about how to run the alert manually using "?run_now=true" something like following:

# curl -u admin:admin -i -H 'X-Requested-By:ambari' -X PUT  http://node1.example.com:8080/api/v1/clusters/ClusterDemo/alert_definitions/151?run_now=true

.

Explorer

@Jay Kumar SenSharma

Referring to the PUT command used for triggering the alert manually, Is it possible to pass some parameters/custom information to the script which gets trigged by the alert ? If yes, is it via headers OR body of the PUT request ?

Thanks.

Expert Contributor

@Jay SenSharma

I know how to deploy a custom monitor and how to start it.

But it runs ok on one server but failed on the other one.

I had change the code to simple logic:

such as:

def execute():
	try:
		return 'OK', 'no errors'
	exception:
		return 'UNKNOW', 'UNKNOW data'

it still shows me :

'NoneType' object has no attribute 'modules' 

And I surely that I can run the monitor.py manaual correctly.

Super Mentor

@darkz yu

There is a typo in UNKNOWN word, Although it might not be causing the issue.

return 'UNKNOW','UNKNOW data'

.

Can you please share the steps that you followed like Where have you placed the script and the sample script, alerts.json. The Ambari Version, I will try the same at my end.

Expert Contributor

I add the script call time to label, and I found there no time return.I will post the script soon

Expert Contributor

test.zip

this the code I run on two server

Super Mentor

@darkz yu


This is the step that i followed:


1). Copied the "flume_monitor.py" script to ambari server "/var/lib/ambari-server/resources/host_scripts" location.

# scp  /Users/jsensharma/Downloads/40443-test/flume_monitor.py   root@amb25101:/var/lib/ambari-server/resources/host_scripts

.

2). Now i pushed the alert definition to my ambari cluster.

# curl -u admin:admin -i -H 'X-Requested-By:ambari' -X POST -d @/Users/jsensharma/Downloads/40443-test/flume_monitor.json  http://amb25101.example.com:8080/api/v1/clusters/plain_ambari/alert_definitions

HTTP/1.1 100 Continue
HTTP/1.1 201 Created
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Cache-Control: no-store
Pragma: no-cache
Set-Cookie: AMBARISESSIONID=j2au8meo5w73182sf1wnjn9z8;Path=/;HttpOnly
Expires: Thu, 01 Jan 1970 00:00:00 GMT
User: admin
Content-Type: text/plain
Content-Length: 0



3). Restarted Ambari Server.

# ambari-server  restart


4). Checked the Ambari UI.

39450-flume-custom-alert.png



My Cluster Details:

[root@amb25101 ambari-server]# ambari-server --version
2.5.1.0-159
[root@amb25101 ambari-server]# python --version
Python 2.7.5

.

Expert Contributor

What I don't clear is why on one server show me

'NoneType' object has no attribute 'modules'

,but the other is ok

I try to restart the ambari-agent,It show me ok

So terrible.

resloved.