Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 4
0
def create_or_get_uri_check(db, url):
    if not (url.startswith('http://') or url.startswith('https://')):
        url = 'http://' + url
    
    try:
        found_check = db.query(UriCheck).filter(UriCheck.url == url).one()
        return found_check
    except NoResultFound:
        #Url is not being monitored, ignore the error and create it
        pass

    check = UriCheck()
    check.url = url 
    check.check_options 

    first_monitor = HashCheck(check)
    try:
        url_stream = urllib2.urlopen(check.url)
        first_monitor.has_changes(url_stream)
    except urllib2.URLError, e:
        if not isinstance(e, urllib2.HTTPError):
            log.error(e.reason)
            return None
Exemplo n.º 5
0
def shutdown_session(exception=None):
    g.db.flush()
    daemonAlertMe.models.Session.remove()

    if not exception is None:
        log.error(u"Request exceptioned out %s: " % exception)