Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ApcupsdCollector also working with apcaccess binary instead of network #734

Open
pzystorm opened this issue Jun 4, 2019 · 0 comments
Open

Comments

@pzystorm
Copy link

pzystorm commented Jun 4, 2019

FYI, ApcupsdCollector is also working locally if there is an apcaccess binary on your system:

--- /usr/local/share/diamond/collectors/apcupsd/apcupsd.py2     2019-06-04 17:16:21.211027758 +0200
+++ /usr/local/share/diamond/collectors/apcupsd/apcupsd.py      2019-06-04 17:16:57.163027758 +0200
@@ -18,6 +18,7 @@
 from struct import pack
 import re
 import time
+import subprocess
 
 
 class ApcupsdCollector(diamond.collector.Collector):
@@ -51,19 +52,22 @@
 
     def getData(self):
         # Get the data via TCP stream
-        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-        s.connect((self.config['hostname'], int(self.config['port'])))
+        #s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        #s.connect((self.config['hostname'], int(self.config['port'])))
 
         # Packet is pad byte, size byte, and command
-        s.send(pack('xb6s', 6, 'status'))
+        #s.send(pack('xb6s', 6, 'status'))
 
         # Ditch the header
-        s.recv(1024)
-        time.sleep(.25)
-        data = s.recv(4096)
+        #s.recv(1024)
+        #time.sleep(.25)
+        #data = s.recv(4096)
 
         # We're done. Close the socket  
-        s.close()  
+        #s.close()
+
+        out_bytes = subprocess.check_output(['apcaccess'])
+        data = out_bytes.decode('utf-8')
         return data
 
     def collect(self):
@@ -72,7 +76,7 @@
 
         data = self.getData()
 
-        data = data.split('\n\x00')
+        data = data.split('\n')
         for d in data:
             matches = re.search("([A-Z]+)\s+:\s+(.*)$", d)
             if matches:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant