def __init__(self, name=None): self.incidents = cachet.Incidents(endpoint=CACHET_API_URL, api_token=CACHET_API_TOKEN, verify=CACHET_SSL_VERIFY) super(CachetIncident, self).__init__(name)
def incident_exists(name, message, status): """ Check if an incident with these attributes already exists """ incidents = cachet.Incidents(endpoint=ENDPOINT) all_incidents = json.loads(incidents.get()) for incident in all_incidents['data']: if name == incident['name'] and \ status == incident['status'] and \ message.strip() == incident['message'].strip(): return True return False
def get_incidents(): res = [] json_data = cachet.Incidents(endpoint=API_ENDPOINT, api_token=API_TOKEN, verify=False).get() incidents = json.loads(json_data) for item in incidents['data']: component_id = item['component_id'] item['component'] = components.get(component_id, None) res.append(item) return res
def createincident(self, name, message, status, notify, visible, component_id, component_status): import cachetclient.cachet as cachet import json incidents = cachet.Incidents(endpoint=Uptime.ENDPOINT, api_token=Uptime.API_TOKEN) temp_incident = json.loads(incidents.post(name=name, message=message, status=status, visible=visible, component_id=component_id, component_status=component_status, notify=notify )) print('incident created') self.FLAG= True # update flag
def create_incident(**kwargs): """ Creates an incident """ incidents = cachet.Incidents(endpoint=ENDPOINT, api_token=API_TOKEN) if 'component_id' in kwargs: return incidents.post(name=kwargs['name'], message=kwargs['message'], status=kwargs['status'], component_id=kwargs['component_id'], component_status=kwargs['component_status']) else: return incidents.post(name=kwargs['name'], message=kwargs['message'], status=kwargs['status'])
def updateincident(self,id, status, message): import cachetclient.cachet as cachet incidents = cachet.Incidents(endpoint=Uptime.ENDPOINT, api_token=Uptime.API_TOKEN) new_incident = incidents.put(id=id, status=status, message=message) print('incident updated') self.FLAG = False # update flag print('The flag is set to:',self.FLAG) component_id = Uptime.get_obj_id(self, self.component_url) # update Uptime.updatecomponent(component_id, Uptime.COMPONENT_STATUS_OPERATIONAL)
def __init__(self): log.info("Initializing incidents manager ...") # Slack self.slack_channel = config['slack']['channel'] self.slack = Slacker(config['slack']['self']['token']) self.slack_self_user = config['slack']['self'] self.slack_fake_user = Slacker(config['slack']['fake_user']['token']) self.apiai_user = self.slack_fake_user.users.info( user=config['slack']['apiai_user']['id']).body['user'] # FIXME SMTP # Elasticsearch log.info("Connecting to Elasticsearch ...") self.es_index = config['elasticsearch']['index'] try: # @formatter:off aws_auth = AWSRequestsAuth( aws_host = config['elasticsearch']['host'], aws_region = config['elasticsearch']['region'], aws_service = 'es', **boto_utils.get_credentials() ) self.es = Elasticsearch( hosts = [{'host': config['elasticsearch']['host'], 'port': 443}], http_auth = aws_auth, use_ssl = True, verify_certs = True, connection_class = RequestsHttpConnection ) # @formatter:on except: log.error("Couldn't connect to Elasticsearch") try: self.create_es_index(self.es_index) except: log.error("Couldn't create Elasticsearch index") # Jira log.info("Connecting to Jira ...") self.jira = JIRA( {'server': config['jira']['host']}, basic_auth=(config['jira']['user'], config['jira']['password']) ) self.jira_project = config['jira']['project'] log.debug("Connecting to Cachet ...") self.cachet_client = cachet.Incidents(endpoint=config['cachet']['host'], api_token=config['cachet']['token']) return
description='Test component')) print(components.get()) components.put(id=new_component['data']['id'], description='Updated component') print(components.get(id=new_component['data']['id'])) components.delete(id=new_component['data']['id']) # /components/groups groups = cachet.Groups(endpoint=ENDPOINT, api_token=API_TOKEN) new_group = json.loads(groups.post(name='Test group')) print(groups.get()) groups.put(id=new_group['data']['id'], name='Updated group') print(groups.get(id=new_group['data']['id'])) groups.delete(new_group['data']['id']) # /incidents incidents = cachet.Incidents(endpoint=ENDPOINT, api_token=API_TOKEN) new_incident = json.loads( incidents.post(name='Test incident', message='Houston, we have a problem.', status=1)) print(incidents.get()) incidents.put(id=new_incident['data']['id'], message="There's another problem, Houston.") print(incidents.get(id=new_incident['data']['id'])) incidents.delete(id=new_incident['data']['id']) # /metrics # /metrics/points metrics = cachet.Metrics(endpoint=ENDPOINT, api_token=API_TOKEN) new_metric = json.loads( metrics.post(name='Test metric',