Esempio n. 1
0
def send_message(alert):
    settings_file = settings.open_settings()

    twilio_enabled = settings_file['settings']['general']['twilio']
    slack_enabled = settings_file['settings']['general']['slack']
    telegram_enabled = settings_file['settings']['general']['telegram']

    if twilio_enabled:
        twilio_settings = settings_file['settings']['twilio']

        client = TwilioRestClient(twilio_settings["account_sid"],
                                  twilio_settings["auth_token"])
        try:
            client.messages.create(body=alert,
                                   to=twilio_settings['mobile_number'],
                                   from_=twilio_settings["twilio_number"])
        except TwilioRestException as e:
            print(e)

    if slack_enabled:
        slack_settings = settings_file['settings']['slack']
        slack_bot.run_bot(alert, slack_settings['channel_name'])

    if telegram_enabled:
        telegram_settings = settings_file['settings']['telegram']
        telegram_bot.run_bot(alert, telegram_settings['id_client'],
                             telegram_settings['bot_token'])
Esempio n. 2
0
    def main(self):
        options_file = settings.open_settings()
        options = options_file['settings']['general']

        if options['twilio']:
            global twilio_settings
            twilio_settings = twilleo.load_twilio_settings()

        if options['slack']:
            global slack_settings
            slack_settings = slack.load_slack_settings()

        if options['telegram']:
            global telegram_settings
            telegram_settings = telegram.load_telegram_settings()

        if settings.check_paranoid_set(options['paranoid']):
            paranoid_setting = options['paranoid']

        screensaver_setting = helpers.set_screensaver(options['screensaver'])

        try:
            self.monitor(paranoid_setting, screensaver_setting)
        except AttributeError:
            print(
                "Unable to start application, mode or screensaver have not been set properly"
            )
Esempio n. 3
0
def send_message(alert):
    logging.debug('Opening settings.json.')
    settings_file = settings.open_settings()
    logging.debug('Getting Twilio settings.')
    twilio_enabled = settings_file['settings']['general']['twilio']
    logging.debug('Getting Slack settings.')
    slack_enabled = settings_file['settings']['general']['slack']
    logging.debug('Getting Pushover settings.')
    pushover_enabled = settings_file['settings']['general']['pushover']
    logging.debug('Getting Telegram settings.')
    telegram_enabled = settings_file['settings']['general']['telegram']

    logging.debug('Checking if Telegram is enabled.')
    if telegram_enabled:
        logging.debug('Opening settings.json.')
        telegram_settings = settings_file['settings']['telegram']
        bot = telepot.Bot(telegram_settings["token"])
        bot.sendMessage(telegram_settings["chat_id"], str(alert))

    logging.debug('Checking if Twilio is enabled.')
    if twilio_enabled:
        logging.debug('Twilio enabled.')
        logging.debug('Loading Twilio settings.')
        twilio_settings = load_twilio_settings()
        logging.debug('Configuring Twilio client.')
        client = TwilioRestClient(twilio_settings["account_sid"],
                                  twilio_settings["auth_token"])
        try:
            logging.debug('Trying to send Twilio message.')
            client.messages.create(body=alert,
                                   to=twilio_settings['mobile_number'],
                                   from_=twilio_settings["twilio_number"])
        except TwilioRestException:
            print(
                'Unable to run application, correct Twilio credentials provided?'
            )
            logging.critical(
                'Aborting... Unable to run application, Twilio credentials incorrect.'
            )
            sys.exit(406)
    logging.debug('Checking if Slack is enabled.')
    if slack_enabled:
        logging.debug('Opening settings.json.')
        slack_settings = load_slack_settings()
        logging.debug('Staring up Slack Bot.')
        slack_bot.run_bot(alert, slack_settings['channel_name'])
    logging.debug('Checking if Pushover is enabled.')
    if pushover_enabled:
        logging.debug('Opening settings.json.')
        pushover_settings = load_pushover_settings()
        client = Client(pushover_settings['user_key'],
                        api_token=pushover_settings['api_token'])
        client.send_message(alert, priority=pushover_settings['priority'])
Esempio n. 4
0
    def main(self):
        options = settings.open_settings()['settings']['general']

        if settings.check_paranoid_setting(options['paranoid']) is True:
            paranoid_enabled = True
        else:
            paranoid_enabled = False

        screensaver_enabled = helpers.set_screensaver(options['screensaver'])

        try:
            while True:
                self.run_canary(paranoid_enabled, screensaver_enabled)
        except AttributeError:
            print('Unable to start application, mode or screensaver has not been set properly')
            sys.exit(506)