Example #1
0
    def send_alerts_for_id(self, check_id, url):
        try:
            twitter_api = twitter.Api(consumer_key=config.TW_CONSUMER_KEY,
                            consumer_secret=config.TW_CONSUMER_SECRET,
                            access_token_key=config.TW_ACCESS_TOKEN,
                            access_token_secret=config.TW_ACCESS_TOKEN_SECRET)

            twitter_api.PostUpdate(u"URL Changed: %s" % url)
            log.info("Tweeted to public stream")

        except twitter.TwitterError, e:
            log.error(u"TwitterError: %s" % e)
Example #2
0
    def _send_tweet(self, target, url):
        try:
            twitter_api = twitter.Api(consumer_key=config.TW_CONSUMER_KEY,
                            consumer_secret=config.TW_CONSUMER_SECRET,
                            access_token_key=config.TW_ACCESS_TOKEN,
                            access_token_secret=config.TW_ACCESS_TOKEN_SECRET)

            twitter_api.PostUpdate(u"%s URL Changed: %s" %
                                        (self._tidy_name(target), url))
            log.info("Tweeted %s to say there was a change" % target)

        except twitter.TwitterError, twe:
            log.error(u"TwitterError: %s" % twe)
Example #3
0
    def run_all(self):
        checks_to_run = self.db_session.query(UriCheck)\
                .from_statement("""SELECT UriChecks.check_id, url, check_type,
                                          check_options, last_check 
                                   FROM UriChecks 
                                   JOIN Alerts AS a ON 
                                       UriChecks.check_id = a.check_id 
                                   WHERE a.stop = 0""").all()
        for check in checks_to_run:
            log.info('about to run check on ' + check.url)
            check.last_check = datetime.datetime.utcnow()

            try:
                hash_check = HashCheck(check)
                url_stream = urllib2.urlopen(check.url)
                if hash_check.has_changes(url_stream):
                    log.info('hash changes requesting alert sent')
                    for alerter in self.alerters:
                        alerter.send_alerts_for_id(check.check_id, check.url)
            except urllib2.URLError, e:
                log.error('unable to query url: %s' % e)
Example #4
0
 def send_alerts_for_id(self, check_id, url):
     for alert in self._get_valid_alerts_by_type(self.ALERT_TYPE, check_id):
         log.info('found someone to tweet @ ' + alert.target)
         self._send_tweet(alert.target, url)
Example #5
0
 def send_alerts_for_id(self, check_id, url):
     for alert in self._get_valid_alerts_by_type(u"email", check_id):
         log.info('found someone to alert ' + alert.target)
         self._create_email(alert, url)