Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

How run default alert script alert_disk_space.py from command line

avatar
Expert Contributor
How  run default alert script alert_disk_space.py   from command line :

[root@serv03
host_scripts]# python alert_disk_space.py
Traceback
(most recent call last):
  File "alert_disk_space.py", line
24, in <module>
   from ambari_commons.os_family_impl import
OsFamilyFuncImpl, OsFamilyImpl
ImportError:
No module named ambari_commons.os_family_impl

------------------------
Notification from Ambari working successfully
1 ACCEPTED SOLUTION

avatar
Master Mentor

@Dmitro Vasilenko

Please set the PYTHONPATH variable before running the ambari python scripts.

Example:

# 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

# /var/lib/ambari-server/resources/host_scripts/alert_disk_space.py
DiskInfo(total=85885063168, used=27091636224, free=58793426944, path='/root')

.

View solution in original post

7 REPLIES 7

avatar
Expert Contributor

Ambari Version 2.5.0.3 (HDP-2.6.3.0)

avatar
Master Mentor

@Dmitro Vasilenko

Please set the PYTHONPATH variable before running the ambari python scripts.

Example:

# 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

# /var/lib/ambari-server/resources/host_scripts/alert_disk_space.py
DiskInfo(total=85885063168, used=27091636224, free=58793426944, path='/root')

.

avatar
Expert Contributor

Hi! Thanks you very match, it works!

avatar
Master Mentor

@Dmitro Vasilenko

Good to know that it worked for you. As the issue is resolved, hence it will be also great if you can mark this HCC thread as Answered by clicking on the "Accept" Button on the correct answer. That way other HCC users can quickly find the solution when they encounter the same issue.

avatar
Expert Contributor

Have another question about your post : "How to create and register custom ambari alerts ?"

How to limit mount point or resolve error : OSError: [Errno 2] No such file or directory: 'net_prio'

[root@serv03 host_scripts]# python test_alert_disk_space.py
mountPoints = ,/sys,/proc,/dev,/sys/kernel/security,/dev/shm,/dev/pts,/run,/sys/fs/cgroup,/sys/fs/cgroup/systemd,/sys/fs/pstore,/sys/fs/cgroup/pids,/sys/fs/cgroup/net_cls,net_prio,/sys/fs/cgroup/perf_event,/sys/fs/cgroup/cpu,cpuacct,/sys/fs/cgroup/devices,/sys/fs/cgroup/hugetlb,/sys/fs/cgroup/blkio,/sys/fs/cgroup/memory,/sys/fs/cgroup/cpuset,/sys/fs/cgroup/freezer,/sys/kernel/config,/,/usr,/proc/sys/fs/binfmt_misc,/dev/mqueue,/sys/kernel/debug,/dev/hugepages,/hadoop,/var,/var/lib,/home,/boot,/proc/sys/fs/binfmt_misc,/run/user/1015,/run/user/1012,/run/user/1031,/run/user/0,/run/user/1029,/run/user/1010,/run/user/1037,/run/user/1013,/run/user/1018,/run/user/1040,/run/user/1022,/run/user/1039
['', '/sys', '/proc', '/dev', '/sys/kernel/security', '/dev/shm', '/dev/pts', '/run', '/sys/fs/cgroup', '/sys/fs/cgroup/systemd', '/sys/fs/pstore', '/sys/fs/cgroup/pids', '/sys/fs/cgroup/net_cls', 'net_prio', '/sys/fs/cgroup/perf_event', '/sys/fs/cgroup/cpu', 'cpuacct', '/sys/fs/cgroup/devices', '/sys/fs/cgroup/hugetlb', '/sys/fs/cgroup/blkio', '/sys/fs/cgroup/memory', '/sys/fs/cgroup/cpuset', '/sys/fs/cgroup/freezer', '/sys/kernel/config', '/', '/usr', '/proc/sys/fs/binfmt_misc', '/dev/mqueue', '/sys/kernel/debug', '/dev/hugepages', '/hadoop', '/var', '/var/lib', '/home', '/boot', '/proc/sys/fs/binfmt_misc', '/run/user/1015', '/run/user/1012', '/run/user/1031', '/run/user/0', '/run/user/1029', '/run/user/1010', '/run/user/1037', '/run/user/1013', '/run/user/1018', '/run/user/1040', '/run/user/1022', '/run/user/1039']
---------- l :
FINAL finalResultCode  CODE .....
---------- l : /sys
/sys
disk_usage.total = 0
=>WARNING
FINAL finalResultCode  CODE .....WARNING
---------- l : /proc
/proc
disk_usage.total = 0
=>WARNING
FINAL finalResultCode  CODE .....WARNING
---------- l : /dev
/dev
disk_usage.total
134933655552
=>WARNING
FINAL finalResultCode  CODE .....WARNING
---------- l : /sys/kernel/security
/sys/kernel/security
disk_usage.total = 0
=>WARNING
FINAL finalResultCode  CODE .....WARNING
---------- l : /dev/shm
/dev/shm
disk_usage.total
134944870400
=>WARNING
FINAL finalResultCode  CODE .....WARNING
---------- l : /dev/pts
/dev/pts
disk_usage.total = 0
=>WARNING
FINAL finalResultCode  CODE .....WARNING
---------- l : /run
/run
disk_usage.total
134944870400
=>WARNING
FINAL finalResultCode  CODE .....WARNING
---------- l : /sys/fs/cgroup
/sys/fs/cgroup
disk_usage.total
134944870400
=>WARNING
FINAL finalResultCode  CODE .....WARNING
---------- l : /sys/fs/cgroup/systemd
/sys/fs/cgroup/systemd
disk_usage.total = 0
=>WARNING
FINAL finalResultCode  CODE .....WARNING
---------- l : /sys/fs/pstore
/sys/fs/pstore
disk_usage.total = 0
=>WARNING
FINAL finalResultCode  CODE .....WARNING
---------- l : /sys/fs/cgroup/pids
/sys/fs/cgroup/pids
disk_usage.total = 0
=>WARNING
FINAL finalResultCode  CODE .....WARNING
---------- l : /sys/fs/cgroup/net_cls
/sys/fs/cgroup/net_cls
disk_usage.total = 0
=>WARNING
FINAL finalResultCode  CODE .....WARNING
---------- l : net_prio
net_prio
Traceback (most recent call last):
  File "test_alert_disk_space.py", line 241, in <module>
    execute()
  File "/usr/lib/python2.6/site-packages/ambari_commons/os_family_impl.py", line 89, in thunk
    return fn(*args, **kwargs)
  File "test_alert_disk_space.py", line 90, in execute
    disk_usage = _get_disk_usage(mountPath)
  File "/usr/lib/python2.6/site-packages/ambari_commons/os_family_impl.py", line 89, in thunk
    return fn(*args, **kwargs)
  File "test_alert_disk_space.py", line 179, in _get_disk_usage
    disk_stats = os.statvfs(path)
OSError: [Errno 2] No such file or directory: 'net_prio'
[root@serv03 host_scripts]#
 

avatar
Master Mentor

@Dmitro Vasilenko

As the original query which was asked in the HCC thread is addressed hence i will suggest you to close this thread by clicking on the "Accept" Button on the correct answer.

Then open a separate HCC thread for your latest query that way it helps in maintaining one thread dedicated to one particular issue/query and helps HCC users to find the correct answers quickly instead of going through side issues.

avatar
Expert Contributor

ok! Thank you!