except Exception as e:
msg.debug("This shouldn't happen. NO " + prefix + " IN LIST:" + str(self.jobs) + " ERROR: " + str(e))
+ # TODO remove section below and remove `reason`.
prefix += ": "
if reason is None:
return
"""
i = 0
overridden = []
+ msg.debug("all job objects", str(self.jobs))
while i < len(self.jobs):
job = self.jobs[i]
try:
if not job.check():
- self._stop(job, "failed check")
+ msg.error(job.chart_name, "check function failed.")
+ self._stop(job)
else:
- msg.debug(job.chart_name, ": check succeeded")
+ msg.debug(job.chart_name, "check succeeded")
i += 1
try:
if job.override_name is not None:
except Exception:
pass
except AttributeError:
- self._stop(job, "no check")
+ self._stop(job)
+ msg.error(job.chart_name, "cannot find check() function.")
except (UnboundLocalError, Exception) as e:
- self._stop(job, "misbehaving. Reason:" + str(e))
+ msg.error(job.chart_name, str(e))
+ self._stop(job)
+ msg.debug("overridden job names:", str(overridden))
+ msg.debug("all remaining job objects:", str(self.jobs))
def create(self):
"""
job = self.jobs[i]
try:
if not job.create():
- self._stop(job, "failed create")
+ msg.error(job.chart_name, "create function failed.")
+ self._stop(job)
else:
chart = job.chart_name
sys.stdout.write(
# sys.stdout.flush()
i += 1
except AttributeError:
- self._stop(job, "no create")
+ msg.error(job.chart_name, "cannot find create() function.")
+ self._stop(job)
except (UnboundLocalError, Exception) as e:
- self._stop(job, "misbehaving. Reason: " + str(e))
+ msg.error(job.chart_name, str(e))
+ self._stop(job)
def update(self):
"""
import sys
import os
import socket
-import resource
try:
import urllib.request as urllib2
except ImportError:
if self.timetable['next'] > t_start:
#msg.debug(self.chart_name + " will be run in " +
# str(int((self.timetable['next'] - t_start) * 1000)) + " ms")
- msg.debug(self.chart_name,"will be run in", str(int((self.timetable['next'] - t_start) * 1000)), "ms")
+ msg.debug(self.chart_name, "will be run in", str(int((self.timetable['next'] - t_start) * 1000)), "ms")
return True
since_last = int((t_start - self.timetable['last']) * 1000000)
"ms (update_every:", str(self.timetable['freq'] * 1000),
"ms, latency:", str(int((t_start - self.timetable['next']) * 1000)), "ms")
if not self.update(since_last):
+ self.error("update function failed.")
return False
t_end = time.time()
self.timetable['next'] = t_end - (t_end % self.timetable['freq']) + self.timetable['freq']
try:
status = self._run_once()
except Exception as e:
- msg.error("Something wrong: " + str(e))
+ msg.error("Something wrong: ", str(e))
return
if status:
time.sleep(self.timetable['next'] - time.time())
else:
time.sleep(self.timetable['freq'])
- def _format(self, *args):
+ @staticmethod
+ def _format(*args):
params = []
append = params.append
for p in args:
"""
data = self._get_data()
if data is None:
+ self.debug("_get_data() returned no data")
return False
updated = False
self.end()
self.commit()
+ if not updated:
+ self.error("no charts to update")
return updated
try:
f = urllib2.urlopen(self.url, timeout=self.update_every)
except Exception as e:
- msg.error(self.__module__, str(e))
+ self.error(str(e))
return None
try:
raw = f.read().decode('utf-8')
except Exception as e:
- msg.error(self.__module__, str(e))
+ self.error(str(e))
finally:
f.close()
return raw
sock.settimeout(0.05) # Just to be sure
except Exception as e:
- self.error(str(e))
+ self.error(str(e), "used configuration: host:", str(self.host), "port:", str(self.port), "socket:", str(self.unix_socket))
self.sock = None
return None
if self.request != "".encode():
try:
sock.send(self.request)
- except Exception:
+ except Exception as e:
try:
sock.shutdown(1)
sock.close()
except:
pass
self.sock = None
+ self.error(str(e), "used configuration: host:", str(self.host), "port:", str(self.port), "socket:", str(self.unix_socket))
return None
size = 2
try:
data = sock.recv(size).decode()
except Exception as e:
- self.error(str(e))
+ self.error(str(e), "used configuration: host:", str(self.host), "port:", str(self.port), "socket:", str(self.unix_socket))
sock.close()
return None
try:
self.unix_socket = str(self.configuration['socket'])
except (KeyError, TypeError):
- self.error("No unix socket specified. Trying TCP/IP socket.")
+ self.debug("No unix socket specified. Trying TCP/IP socket.")
try:
self.host = str(self.configuration['host'])
except (KeyError, TypeError):
- self.error("No host specified. Using: '" + self.host + "'")
+ self.debug("No host specified. Using: '" + self.host + "'")
try:
self.port = int(self.configuration['port'])
except (KeyError, TypeError):
- self.error("No port specified. Using: '" + str(self.port) + "'")
+ self.debug("No port specified. Using: '" + str(self.port) + "'")
try:
self.request = str(self.configuration['request'])
except (KeyError, TypeError):
- self.error("No request specified. Using: '" + str(self.request) + "'")
+ self.debug("No request specified. Using: '" + str(self.request) + "'")
self.request = self.request.encode()
if os.path.getsize(self.log_path) < self._last_position:
self._last_position = 0
elif os.path.getsize(self.log_path) == self._last_position:
+ self.debug("Log file hasn't changed. No new data.")
return None
with open(self.log_path, "r") as fp:
fp.seek(self._last_position)
lines.append(line)
self._last_position = fp.tell()
except Exception as e:
- self.error(self.__module__, str(e))
+ self.error(str(e))
if len(lines) != 0:
return lines
- return None
+ else:
+ self.error("No data collected.")
+ return None
def check(self):
"""
try:
p = Popen(self.command, stdout=PIPE, stderr=PIPE)
except Exception as e:
- self.error(self.__module__, str(e))
+ self.error(str(e))
return None
data = []
for line in p.stdout.readlines():
data.append(str(line.decode()))
if len(data) == 0:
+ self.error("No data collected.")
return None
return data