コード例 #1
0
 def test_user_equality(self):
     from charlesbot.slack.slack_user import SlackUser
     user1 = SlackUser(id="SU01", name="userone", color="red")
     user2 = SlackUser(id="SU02", name="usertwo", color="blue")
     self.assertNotEqual(user1, user2)
     user2.id = "SU01"
     self.assertNotEqual(user1, user2)
     user2.name = "userone"
     self.assertNotEqual(user1, user2)
     user2.color = "red"
     self.assertEqual(user1, user2)
    def trigger_escalation_incident(self, parsed_message, slack_message_obj):
        """
        Trigger a service escalation for the specified service
        """
        # This parses the service string into two components: the service name
        # and optional service message.
        # e.g. website please call me --> ['website', 'please call me']
        # e.g. website --> ['website']
        # e.g. website plz --> ['website', 'plz']
        full_service_str = parsed_message.strip()
        service_str_components = full_service_str.split(' ', 1)

        # Check to see if the service key exists
        service_name = service_str_components[0]
        service_key = self.pd_service_mappings.get(service_name)
        if not service_key:
            error_msg = "Could not find key for service '%s', check that the service exists in the config file!" % service_name  # NOQA
            self.log.error(error_msg)
            yield from self.slack.send_channel_message(
                slack_message_obj.channel, error_msg)  # NOQA
            return

        slack_user = SlackUser()
        yield from slack_user.retrieve_slack_user_info(self.slack,
                                                       slack_message_obj.user)

        # Set the custom trigger message, if one was provided
        custom_message = ""
        try:
            custom_message = service_str_components[1]
        except IndexError:
            pass

        payload = self.get_trigger_payload(service_key,
                                           service_name,
                                           slack_user.real_name,
                                           custom_message=custom_message)
        response = yield from http_post_request(
            url=
            "https://events.pagerduty.com/generic/2010-04-15/create_event.json",  # NOQA
            payload=json.dumps(payload),
        )
        if not response:
            error_msg = "Could not escalate incident for %s. Check the logs for details." % service_name  # NOQA
            self.log.error(error_msg)
            yield from self.slack.send_channel_message(
                slack_message_obj.channel, error_msg)  # NOQA
            return

        success_msg = "Successfully escalated this %s incident!" % service_name
        self.log.info(success_msg)
        yield from self.slack.send_channel_message(slack_message_obj.channel,
                                                   success_msg)
コード例 #3
0
    def setUp(self):
        patcher1 = patch(
            'charlesbot.slack.slack_connection.SlackConnection.api_call'
        )  # NOQA
        self.addCleanup(patcher1.stop)
        self.mock_api_call = patcher1.start()

        from charlesbot.slack.slack_connection import SlackConnection
        self.slack_connection = SlackConnection()

        from charlesbot.slack.slack_user import SlackUser
        self.su = SlackUser()
コード例 #4
0
    def setUp(self):
        patcher1 = patch(
            'charlesbot_broadcast_message.broadcast_message.BroadcastMessage.seed_initial_data'
        )  # NOQA
        self.addCleanup(patcher1.stop)
        self.mock_seed_initial_data = patcher1.start()

        patcher2 = patch(
            'charlesbot.slack.slack_connection.SlackConnection.api_call'
        )  # NOQA
        self.addCleanup(patcher2.stop)
        self.mock_api_call = patcher2.start()

        from charlesbot_broadcast_message.broadcast_message import BroadcastMessage  # NOQA
        self.bm = BroadcastMessage()

        self.expected_attachment = SlackAttachment(
            fallback="Broadcast message from bob - message",
            author_name="bob",
            author_icon="tumb",
            text="message")
        self.su = SlackUser(real_name="bob", image_24="tumb")