]> arthur.barton.de Git - netdata.git/blobdiff - python.d/freeradius.chart.py
Merge pull request #1763 from ktsaou/master
[netdata.git] / python.d / freeradius.chart.py
index 829c14cb6a3b45d4c310fa4519045167b68471c2..001147cef06e37c327f6abd30a27a72cef9b2157 100644 (file)
@@ -3,7 +3,6 @@
 # Author: l2isbad
 
 from base import SimpleService
-from os.path import isfile
 from re import findall
 from subprocess import Popen, PIPE
 
@@ -11,7 +10,6 @@ from subprocess import Popen, PIPE
 priority = 60000
 retries = 60
 update_every = 15
-directories = ['/bin/', '/usr/bin/', '/sbin/', '/usr/sbin/']
 
 # charts order (can be overridden if you want less charts, or different order)
 ORDER = ['authentication', 'accounting', 'proxy-auth', 'proxy-acct']
@@ -62,14 +60,14 @@ class Service(SimpleService):
         self.acct = self.configuration.get('acct', False)
         self.proxy_auth = self.configuration.get('proxy_auth', False)
         self.proxy_acct = self.configuration.get('proxy_acct', False)
-        self.echo = [''.join([directory, 'echo']) for directory in directories if isfile(''.join([directory, 'echo']))][0]
-        self.radclient = [''.join([directory, 'radclient']) for directory in directories if isfile(''.join([directory, 'radclient']))][0]
+        self.echo = self.find_binary('echo')
+        self.radclient = self.find_binary('radclient')
         self.sub_echo = [self.echo, 'Message-Authenticator = 0x00, FreeRADIUS-Statistics-Type = 15, Response-Packet-Type = Access-Accept']
         self.sub_radclient = [self.radclient, '-r', '1', '-t', '1', ':'.join([self.host, self.port]), 'status', self.secret]
     
     def check(self):
         if not all([self.echo, self.radclient]):
-            self.error('Command radclient not found')
+            self.error('Can\'t locate \'radclient\' binary or binary is not executable by netdata')
             return False
         if self._get_raw_data():
             chart_choice = [True, bool(self.acct), bool(self.proxy_auth), bool(self.proxy_acct)]
@@ -97,8 +95,8 @@ class Service(SimpleService):
         :return: str
         """
         try:
-            process_echo = Popen(self.sub_echo,  stdout=PIPE, shell=False)
-            process_rad = Popen(self.sub_radclient, stdin=process_echo.stdout, stdout=PIPE,  shell=False)
+            process_echo = Popen(self.sub_echo, stdout=PIPE, stderr=PIPE, shell=False)
+            process_rad = Popen(self.sub_radclient, stdin=process_echo.stdout, stdout=PIPE, stderr=PIPE, shell=False)
             process_echo.stdout.close()
             raw_result = process_rad.communicate()[0]
         except Exception: