Aug-11-2017, 01:25 AM
Hi All,
I have this script that gives me a bunch of errors Please help. Am new to python
I have this script that gives me a bunch of errors Please help. Am new to python
>>> ... def create_zendesk_ticket(self,event_id,event_status): File "<stdin>", line 2 def create_zendesk_ticket(self,event_id,event_status): ^ IndentationError: unexpected indent >>> collaborators = self.zbx_evt_recipients(event_id) File "<stdin>", line 1 collaborators = self.zbx_evt_recipients(event_id) ^ IndentationError: unexpected indent >>> subject = self.ydata['trigger']['name'] File "<stdin>", line 1 subject = self.ydata['trigger']['name'] ^ IndentationError: unexpected indent >>> #description = '%s\n\nZabbix severity: %s' % (self.ydata['desc'],self.ydata['trigger']['severity']) ... description = self.ydata['desc'].replace('"','') File "<stdin>", line 2 description = self.ydata['desc'].replace('"','') ^ IndentationError: unexpected indent >>> priority = 'high' if self.ydata['trigger']['severity'] == 'High' else 'normal' File "<stdin>", line 1 priority = 'high' if self.ydata['trigger']['severity'] == 'High' else 'normal' ^ IndentationError: unexpected indent >>> tkt_data = { 'ticket': { File "<stdin>", line 1 tkt_data = { 'ticket': { ^ IndentationError: unexpected indent >>> 'subject': subject, File "<stdin>", line 1 'subject': subject, ^ IndentationError: unexpected indent >>> 'description': description, File "<stdin>", line 1 'description': description, ^ IndentationError: unexpected indent >>> 'collaborators': collaborators, File "<stdin>", line 1 'collaborators': collaborators, ^ IndentationError: unexpected indent >>> 'set_tags': ['test'], File "<stdin>", line 1 'set_tags': ['test'], ^ IndentationError: unexpected indent >>> 'external_id': event_id, File "<stdin>", line 1 'external_id': event_id, ^ IndentationError: unexpected indent >>> 'priority': priority, File "<stdin>", line 1 'priority': priority, ^ IndentationError: unexpected indent >>> 'requester_id': self.zd_enduser['id'], File "<stdin>", line 1 'requester_id': self.zd_enduser['id'], ^ IndentationError: unexpected indent >>> 'submitter_id': self.zd_enduser['id'], File "<stdin>", line 1 'submitter_id': self.zd_enduser['id'], ^ IndentationError: unexpected indent >>> 'organization_id': self.zd_enduser['organization_id'], File "<stdin>", line 1 'organization_id': self.zd_enduser['organization_id'], ^ IndentationError: unexpected indent >>> }} File "<stdin>", line 1 }} ^ IndentationError: unexpected indent >>> ### Auto-close if status is "OK" and severity is "information" ... if event_status == 'OK' and self.ydata['trigger']['severity'] == 'Information': File "<stdin>", line 2 if event_status == 'OK' and self.ydata['trigger']['severity'] == 'Information': ^ IndentationError: unexpected indent >>> tkt_data['ticket']['status'] = 'solved' File "<stdin>", line 1 tkt_data['ticket']['status'] = 'solved' ^ IndentationError: unexpected indent >>> tkt_data['ticket']['assignee_id'] = self.zd_user['id'] File "<stdin>", line 1 tkt_data['ticket']['assignee_id'] = self.zd_user['id'] ^ IndentationError: unexpected indent >>> >>> ### TODO: ADD TKT_ID as acknowledge comment ... tkt_url = self.zd.create_ticket(data=tkt_data) File "<stdin>", line 2 tkt_url = self.zd.create_ticket(data=tkt_data) ^ IndentationError: unexpected indent >>> tkt_id = get_id_from_url(tkt_url) File "<stdin>", line 1 tkt_id = get_id_from_url(tkt_url) ^ IndentationError: unexpected indent >>> #tkt = self.zd.show_ticket(ticket_id=tkt_id) ... #log.debug('Created ticket with ID %s'%tkt_id) ... #log.debug(json.dumps(tkt,sort_keys=True,indent=2)) ... log.info('Created Zendesk ticket ID %s from Zabbix eventid %s' % (tkt_id,event_id)) File "<stdin>", line 4 log.info('Created Zendesk ticket ID %s from Zabbix eventid %s' % (tkt_id,event_id)) ^ IndentationError: unexpected indent >>> #return tkt_id ... >>> >>> def update_zendesk_ticket(self,event_id,event_status): File "<stdin>", line 1 def update_zendesk_ticket(self,event_id,event_status): ^ IndentationError: unexpected indent >>> if event_status == 'OK': File "<stdin>", line 1 if event_status == 'OK': ^ IndentationError: unexpected indent >>> tkt = self.zd.list_all_tickets(external_id=event_id) File "<stdin>", line 1 tkt = self.zd.list_all_tickets(external_id=event_id) ^ IndentationError: unexpected indent >>> log.debug(tkt) # json.dumps(tkt,sort_keys=True,indent=2) File "<stdin>", line 1 log.debug(tkt) # json.dumps(tkt,sort_keys=True,indent=2) ^ IndentationError: unexpected indent >>> if tkt['count']==1: File "<stdin>", line 1 if tkt['count']==1: ^ IndentationError: unexpected indent >>> tkt_id = tkt['tickets'][0]['id'] File "<stdin>", line 1 tkt_id = tkt['tickets'][0]['id'] ^ IndentationError: unexpected indent >>> desc = self.ydata['desc'].replace('"','') File "<stdin>", line 1 desc = self.ydata['desc'].replace('"','') ^ IndentationError: unexpected indent >>> #log.info('Update ticket %s' % tkt_id) ... if self.ydata['trigger']['severity'] == 'High': File "<stdin>", line 2 if self.ydata['trigger']['severity'] == 'High': ^ IndentationError: unexpected indent >>> tkt_data = {'ticket':{ File "<stdin>", line 1 tkt_data = {'ticket':{ ^ IndentationError: unexpected indent >>> 'comment':{'public':True, 'body': desc} File "<stdin>", line 1 'comment':{'public':True, 'body': desc} ^ IndentationError: unexpected indent >>> }} File "<stdin>", line 1 }} ^ IndentationError: unexpected indent >>> log.info('Updating ticket %s from Zabbix event %s' % (tkt_id,event_id)) File "<stdin>", line 1 log.info('Updating ticket %s from Zabbix event %s' % (tkt_id,event_id)) ^ IndentationError: unexpected indent >>> else: File "<stdin>", line 1 else: ^ IndentationError: unexpected indent >>> tkt_data = {'ticket':{ File "<stdin>", line 1 tkt_data = {'ticket':{ ^ IndentationError: unexpected indent >>> 'status': 'solved', File "<stdin>", line 1 'status': 'solved', ^ IndentationError: unexpected indent >>> 'assignee_id': self.zd_user['id'], File "<stdin>", line 1 'assignee_id': self.zd_user['id'], ^ IndentationError: unexpected indent >>> 'comment':{ File "<stdin>", line 1 'comment':{ ^ IndentationError: unexpected indent >>> 'public':True, File "<stdin>", line 1 'public':True, ^ IndentationError: unexpected indent >>> 'author_id': self.zd_enduser['id'], File "<stdin>", line 1 'author_id': self.zd_enduser['id'], ^ IndentationError: unexpected indent >>> 'body': '%s\n(Auto-closed by Zabbix)'%desc File "<stdin>", line 1 'body': '%s\n(Auto-closed by Zabbix)'%desc ^ IndentationError: unexpected indent >>> } File "<stdin>", line 1 } ^ IndentationError: unexpected indent >>> }} File "<stdin>", line 1 }} ^ IndentationError: unexpected indent >>> log.info('Closing Zendesk ticket %s, event id: %s' % (tkt_id,event_id)) File "<stdin>", line 1 log.info('Closing Zendesk ticket %s, event id: %s' % (tkt_id,event_id)) ^ IndentationError: unexpected indent >>> >>> tkt_up = self.zd.update_ticket(ticket_id=tkt_id,data=tkt_data) File "<stdin>", line 1 tkt_up = self.zd.update_ticket(ticket_id=tkt_id,data=tkt_data) ^ IndentationError: unexpected indent >>> #log.debug(json.dumps(tkt_up,sort_keys=True,indent=2)) ... return True File "<stdin>", line 2 return True ^ IndentationError: unexpected indent >>> return False File "<stdin>", line 1 return False ^ IndentationError: unexpected indent >>> >>> ... def mysql_s File "<stdin>", line 2 def mysql_s ^ IndentationError: unexpected indent >>> try: File "<stdin>", line 1 try: ^ IndentationError: unexpected indent >>> # Get MySQL connection parameters from zabbix conf file ... with open(self.zabbix_conf) as f: File "<stdin>", line 2 with open(self.zabbix_conf) as f: ^ IndentationError: unexpected indent >>> my = dic File "<stdin>", line 1 my = dic ^ IndentationError: unexpected indent >>> f.read().split('\n') if ln. File "<stdin>", line 1 f.read().split('\n') if ln. ^ IndentationError: unexpected indent >>> self.db = MySQLdb.connect(my['host'], my['user'], my['password'], my['name']) File "<stdin>", line 1 self.db = MySQLdb.connect(my['host'], my['user'], my['password'], my['name']) ^ IndentationError: unexpected indent >>> self.mycsr = self.db.cursor() File "<stdin>", line 1 self.mycsr = self.db.cursor() ^ IndentationError: unexpected indent >>> except IOError as e: File "<stdin>", line 1 except IOError as e: ^ IndentationError: unexpected indent >>> log.error(e) File "<stdin>", line 1 log.error(e) ^ IndentationError: unexpected indent >>> return False File "<stdin>", line 1 return False ^ IndentationError: unexpected indent >>> except KeyError as e: File "<stdin>", line 1 except KeyError as e: ^ IndentationError: unexpected indent >>> log.error('Could not find %s'%e) File "<stdin>", line 1 log.error('Could not find %s'%e) ^ IndentationError: unexpected indent >>> return False File "<stdin>", line 1 return False ^ IndentationError: unexpected indent >>> else: File "<stdin>", line 1 else: ^ IndentationError: unexpected indent >>> return True File "<stdin>", line 1 return True ^ IndentationError: unexpected indent >>> >>> >>> def get_zendesk_user(self,email): File "<stdin>", line 1 def get_zendesk_user(self,email): ^ IndentationError: unexpected indent >>> cache_file = '/tmp/zendesk_user_%s' % email File "<stdin>", line 1 cache_file = '/tmp/zendesk_user_%s' % email ^ IndentationError: unexpected indent >>> try: File "<stdin>", line 1 try: ^ IndentationError: unexpected indent >>> if time()-path.getmtime(cache_file) > 86400: File "<stdin>", line 1 if time()-path.getmtime(cache_file) > 86400: ^ IndentationError: unexpected indent >>> remove(cache_file) File "<stdin>", line 1 remove(cache_file) ^ IndentationError: unexpected indent >>> log.debug('Cache file deleted') File "<stdin>", line 1 log.debug('Cache file deleted') ^ IndentationError: unexpected indent >>> with open(cache_file, 'r') as f: File "<stdin>", line 1 with open(cache_file, 'r') as f: ^ IndentationError: unexpected indent >>> data = yaml.load(f.read()) File "<stdin>", line 1 data = yaml.load(f.read()) ^ IndentationError: unexpected indent >>> except: File "<stdin>", line 1 except: ^ IndentationError: unexpected indent >>> data = self.zd.search_user(query='email:%s'%email)['users'][0] File "<stdin>", line 1 data = self.zd.search_user(query='email:%s'%email)['users'][0] ^ IndentationError: unexpected indent >>> with open(cache_file, 'w') as f: File "<stdin>", line 1 with open(cache_file, 'w') as f: ^ IndentationError: unexpected indent >>> f.write(yaml.dump(data) ) File "<stdin>", line 1 f.write(yaml.dump(data) ) ^ IndentationError: unexpected indent >>> ... return data File "<stdin>", line 2 return data ^ IndentationError: unexpected indent >>> ... >>> def zbx_evt_recipients(self,event_id): File "<stdin>", line 1 def zbx_evt_recipients(self,event_id): ^ IndentationError: unexpected indent >>> rows = ['[email protected]'] File "<stdin>", line 1 rows = ['[email protected]'] ^ IndentationError: unexpected indent >>> try: File "<stdin>", line 1 try: ^ IndentationError: unexpected indent >>> sql = """SELECT m.sendto mail File "<stdin>", line 1 sql = """SELECT m.sendto mail ^ IndentationError: unexpected indent >>> FROM events e,functions f,items i, hosts_groups hg, groups g, users_groups uxg, usrgrp ug, media m File "<stdin>", line 1 FROM events e,functions f,items i, hosts_groups hg, groups g, users_groups uxg, usrgrp ug, media m ^ SyntaxError: invalid syntax >>> WHERE e.eventid=%s File "<stdin>", line 1 WHERE e.eventid=%s ^ SyntaxError: invalid syntax >>> AND e.object=0 File "<stdin>", line 1 AND e.object=0 ^ SyntaxError: invalid syntax >>> AND e.source=0 File "<stdin>", line 1 AND e.source=0 ^ SyntaxError: invalid syntax >>> AND e.objectid=f.triggerid File "<stdin>", line 1 AND e.objectid=f.triggerid ^ SyntaxError: invalid syntax >>> AND f.itemid=i.itemid File "<stdin>", line 1 AND f.itemid=i.itemid ^ SyntaxError: invalid syntax >>> AND hg.hostid=i.hostid File "<stdin>", line 1 AND hg.hostid=i.hostid ^ SyntaxError: invalid syntax >>> AND ug.usrgrpid=uxg.usrgrpid File "<stdin>", line 1 AND ug.usrgrpid=uxg.usrgrpid ^ SyntaxError: invalid syntax >>> AND m.userid=uxg.userid File "<stdin>", line 1 AND m.userid=uxg.userid ^ SyntaxError: invalid syntax >>> AND LOWER(g.name)=LOWER(ug.name) File "<stdin>", line 1 AND LOWER(g.name)=LOWER(ug.name) ^ SyntaxError: invalid syntax >>> AND hg.groupid=g.groupid;""" File "<stdin>", line 1 AND hg.groupid=g.groupid;""" ^ SyntaxError: invalid syntax >>> self.mycsr.execute(sql % event_id) File "<stdin>", line 1 self.mycsr.execute(sql % event_id) ^ IndentationError: unexpected indent >>> rows.extend([ r[0] for r in self.mycsr.fetchall() ]) File "<stdin>", line 1 rows.extend([ r[0] for r in self.mycsr.fetchall() ]) ^ IndentationError: unexpected indent >>> return rows File "<stdin>", line 1 return rows ^ IndentationError: unexpected indent >>> except: File "<stdin>", line 1 except: ^ IndentationError: unexpected indent >>> return rows File "<stdin>", line 1 return rows ^ IndentationError: unexpected indent >>> >>> ### END OF CLASS ### ... >>> if __name__ == '__main__': ... try: ... exit(z2z()) ... except Exception as e: ... log.error(e)