def read_secrets(config='/etc/zm/secrets.ini'): from configparser import ConfigParser secrets_object = ConfigParser(interpolation=None,inline_comment_prefixes='#') secrets_object.optionxform=str zmlog.Debug(1,'eid:{} Reading secrets from {}'.format(eid,config)) with open(config) as f: secrets_object.read_file(f) return secrets_object._sections['secrets']
def debug(self, msg, level=1): idx = min(len(stack()), 1) caller = getframeinfo(stack()[idx][0]) zmlog.Debug(level, msg, caller) if (self.dump_console): print('CONSOLE:' + msg)
eid = sys.argv[2] mid = sys.argv[3] mname = sys.argv[4] cause = sys.argv[5] image_path = sys.argv[7] fname=get_image(image_path, cause) # read parameters from secrets secrets = read_secrets() passwd = secrets.get('FTP_PASSWORD') user = secrets.get('FTP_USERNAME') server = secrets.get('FTP_SERVER') careaboutlist = secrets.get('FTP_CAREABOUT').split(',') dirBase = secrets.get('FTP_BASEDIR') zmlog.Debug(1,"eid:{} FTP {} to {} as {}".format(eid,fname,server,user)) preExt,fileExt= os.path.splitext(fname) #See if object we care about is in the list reason = None for item in careaboutlist: if item in cause: if reason is None: reason = item else: reason = reason + "-" + item # Only FTP if file matches something we care about if not reason: zmlog.Info('eid:{} File not transfered as cause[{}] did not match care about list [{}]'.format(eid,cause, careaboutlist))
zmlog.close() exit(1) eid = sys.argv[1] mid = sys.argv[2] mname = sys.argv[3] cause = sys.argv[4] event_type = sys.argv[5] image_path = None files = None if len(sys.argv) == 7: image_path = sys.argv[6] fname = get_image(image_path, cause) zmlog.Debug(1, 'eid:{} Image to be used is: {}'.format(eid, fname)) f, e = os.path.splitext(fname) if e.lower() == '.mp4': ctype = 'video/mp4' else: ctype = 'image/jpeg' zmlog.Debug( 1, 'Setting ctype to {} for extension {}'.format(ctype, e.lower())) files = {"attachment": ("image" + e.lower(), open(fname, "rb"), ctype)} if not param_dict['token'] or param_dict['user']: # read from secrets secrets = read_secrets() if not param_dict['token']: param_dict['token'] = secrets.get('PUSHOVER_APP_TOKEN') zmlog.Debug(1, "eid:{} Reading token from secrets".format(eid))
format(len(sys.argv) - 1, sys.argv)) zmlog.close() exit(1) eid = sys.argv[1] mid = sys.argv[2] mname = sys.argv[3] cause = sys.argv[4] event_type = sys.argv[5] image_path = None files = None if len(sys.argv) == 7: image_path = sys.argv[6] fname = get_image(image_path, cause) zmlog.Debug(1, 'eid:{} Image to be used is: {}'.format(eid, fname)) files = {"attachment": ("image.jpg", open(fname, "rb"), "image/jpeg")} if not param_dict['token'] or param_dict['user']: # read from secrets secrets = read_secrets() if not param_dict['token']: param_dict['token'] = secrets.get('PUSHOVER_APP_TOKEN') print(param_dict['token']) zmlog.Debug(1, "eid:{} Reading token from secrets".format(eid)) if not param_dict['user']: param_dict['user'] = secrets.get('PUSHOVER_USER_KEY'), zmlog.Debug(1, "eid:{} Reading user from secrets".format(eid)) param_dict['title'] = '{} Alarm ({})'.format(mname, eid) param_dict['message'] = cause + datetime.now().strftime(' at %I:%M %p, %b-%d')
'Missing arguments, got {} arguments, was expecting at least 6: {}'. format(len(sys.argv) - 1, sys.argv)) zmlog.close() exit(1) eid = sys.argv[1] mid = sys.argv[2] mname = sys.argv[3] cause = sys.argv[4] event_type = sys.argv[5] image_path = None files = None if len(sys.argv) == 7: image_path = sys.argv[6] fname = get_image(image_path, cause) zmlog.Debug(1, 'Image to be used is: {}'.format(fname)) files = {"attachment": ("image.jpg", open(fname, "rb"), "image/jpeg")} param_dict['title'] = '{} Alarm ({})'.format(mname, eid) param_dict['message'] = cause if event_type == 'event_end': param_dict['title'] = 'Ended:' + param_dict['title'] r = requests.post("https://api.pushover.net/1/messages.json", data=param_dict, files=files) print(r.text) zmlog.close()
def debug(self, msg): idx = min(len(stack()), 1) caller = getframeinfo(stack()[idx][0]) zmlog.Debug(1, msg, caller)