def notify(self, msg):
        """Docstring.

           Init: "Welcome to SecureTea..!! Initializing System"
           Intrusion detector: "(Count) Someone has access your laptop"

        Args:
            msg (TYPE): Description
        """
        message = (str(msg) + " at " + common.getdatetime() +
                   " " + common.get_current_location() + common.get_platform())

        html_str = "<html><head></head><body><h1>Security Alert</h1><p>"+message+"</p></body></html>"
        self.email_obj.html(html_str)
        typ, typ_desc = self.email_obj.send()
        if typ == "Ok":
            self.logger.log(
                "Notification sent, Message Id: "+
                str(typ_desc)
            )
        else:
            self.logger.log(
                "Aws SES notification not sent, error is: " +
                str(typ_desc),
                logtype="error"
            )
        return
Example #2
0
    def notify(self, msg):
        """
        Send the notification.

        Args:
            msg (str): Message to send

        Raises:
            None

        Returns:
            None
        """
        message = (str(msg) + " at " + common.getdatetime() +
                   " " + common.get_current_location() + common.get_platform())

        html_str = ("<html><head></head><body><h1>Security Alert</h1><p>" +
                    message +
                    "</p></body></html>")

        self.email_obj.html(html_str)
        typ, typ_desc = self.email_obj.send()
        if typ == "Ok":
            self.logger.log(
                "Notification sent, message ID: " +
                str(typ_desc)
            )
        else:
            self.logger.log(
                "Aws SES notification not sent, error is: " +
                str(typ_desc),
                logtype="error"
            )
        return
Example #3
0
    def notify(self, msg):
        """Docstring.

           Init: "Welcome to SecureTea..!! Initializing System"
           Intrusion detector: "(Count) Someone has access your laptop"

        Args:
            msg (TYPE): Description
        """
        message = str(msg) + " at " + common.getdatetime()
        channel_info = requests.post(self.slack_channel_open_url,
                                     headers={
                                         "Authorization": self.auth_header
                                     },
                                     data={
                                         "user": self.user_id
                                     }).json()
        channel_id = channel_info['channel']['id']

        post_message = requests.post(self.slack_post_message_url,
                                     headers={
                                         "Authorization": self.auth_header
                                     },
                                     data={
                                         "channel": channel_id,
                                         "text": message
                                     }).json()

        if post_message['ok'] is True:
            self.logger.log("Notification sent")
        else:
            self.logger.log("Slack notification not sent, error is: " +
                            str(post_message['error']),
                            logtype="error")
        return
Example #4
0
    def notify(self, msg):
        """Docstring.

        Args:
            msg (TYPE): Description
        """
        message = str(msg) + " at " + common.getdatetime()
        bot = telegram.Bot(token=self.token)
        bot.send_message(chat_id=self.user_id, text=message)
        self.logger.log("Notification sent")
        return
Example #5
0
    def generatemessage(msg):
        """
        Generate message by attaching the current CPU time.

        Args:
            msg (str): Message to send

        Returns:
            messsage (str): Message appended with CPU time
        """
        message = (str(msg) + " at " + common.getdatetime() + " " +
                   common.get_current_location() + common.get_platform())

        return message
Example #6
0
    def generatemessage(msg):
        """
        Generate message by attaching the current CPU time.

        Args:
        -----
        :msg : str
            Message to send

        Returns:
        --------
        str: Message appended with CPU time
        """
        message = str(msg) + " at " + common.getdatetime()

        return message
Example #7
0
    def notify(self, msg):
        """
        Send the notification.

        Args:
            msg (str): Message to send

        Raises:
            None

        Returns:
            None
        """
        try:
            message = (str(msg) + " at " + common.getdatetime() + " " +
                       common.get_current_location() + common.get_platform())
            data = {
                "event": {
                    "type": "message_create",
                    "message_create": {
                        "target": {
                            "recipient_id": self.id
                        },
                        "message_data": {
                            "text": message
                        }
                    }
                }
            }

            endpoint = "/direct_messages/events/new.json"
            response = requests.post(self.baseUrl + endpoint,
                                     auth=self.auth,
                                     data=json.dumps(data))
            if response.status_code == 200:
                self.logger.log("Notification sent")
            else:
                self.logger.log("Notification not sent, error is: " +
                                str(response.text),
                                logtype="error")
            return
        except Exception as e:
            self.logger.log("Exception in notification sent, error is: " +
                            str(e),
                            logtype="error")
        return
Example #8
0
    def notify(self, msg):
        """Docstring.

        Args:
            msg (TYPE): Description
        """
        try:
            message = str(msg) + " at " + common.getdatetime()
            data = {
                "event": {
                    "type": "message_create",
                    "message_create": {
                        "target": {
                            "recipient_id": self.id
                        },
                        "message_data": {
                            "text": message
                        }
                    }
                }
            }

            endpoint = "/direct_messages/events/new.json"
            response = requests.post(
                self.baseUrl + endpoint,
                auth=self.auth,
                data=json.dumps(data)
            )
            if response.status_code == 200:
                self.logger.log(
                    "Notification sent"
                )
            else:
                self.logger.log(
                    "Notification not sent, error is: " + str(response.text),
                    logtype="error"
                )
            return
        except Exception as e:
            self.logger.log(
                "Exception in notification sent, error is: " + str(e),
                logtype="error"
            )
        return
Example #9
0
    def notify(self, msg):
        """
        Send the notification.

        Args:
            msg (str): Message to send

        Raises:
            None

        Returns:
            None
        """
        message = (str(msg) + " at " + common.getdatetime() + " " +
                   common.get_current_location() + common.get_platform())

        channel_info = requests.post(self.slack_channel_open_url,
                                     headers={
                                         "Authorization": self.auth_header
                                     },
                                     data={
                                         "user": self.user_id
                                     }).json()
        channel_id = channel_info['channel']['id']

        post_message = requests.post(self.slack_post_message_url,
                                     headers={
                                         "Authorization": self.auth_header
                                     },
                                     data={
                                         "channel": channel_id,
                                         "text": message
                                     }).json()

        if post_message['ok'] is True:
            self.logger.log("Notification sent")
        else:
            self.logger.log("Slack notification not sent, error is: " +
                            str(post_message['error']),
                            logtype="error")
        return
    def generate_message(self, msg):
        """
        Generate message to send.

        Args:
            msg (str): Message to add time-stamp & geo-loc to

        Raises:
            None

        Returns:
            body (str): Generated message
        """
        body = '\r\n'.join(['To: %s' % self.to_email,
                            'From: %s' % self.sender_email,
                            'Subject: (Alert) Intrusion Detected!' + " at " +
                            common.getdatetime() +
                            " " + common.get_current_location() + " " +
                            common.get_platform(),
                            '', msg])
        return body
    def notify(self, msg):
        """
        Send the notification.

        Args:
            msg (str): Message to send

        Raises:
            None

        Returns:
            None
        """
        message = (str(msg) + " at " + common.getdatetime() +
                   " " + common.get_current_location() + common.get_platform())

        bot = telegram.Bot(token=self.token)
        bot.send_message(chat_id=self.user_id, text=message)
        self.logger.log(
            "Notification sent"
        )
        return
Example #12
0
 def test_getdatetime(self):
     """
     Test getdatetime.
     """
     pc_time = str(time.strftime("%Y-%m-%d %H:%M:%S"))
     self.assertEqual(pc_time, common.getdatetime())