Beispiel #1
0
    def _add_monitor(self, r, monitor, beat):
        if monitor.name in r.user.monitors.keys():
            raise ValidationFailedException(dict(name='Check with name "%s" already exist' % monitor.name))
        
        if monitor.config in [m.config for m in r.user.monitors.values()]:
            raise ValidationFailedException(dict(url='You already have a check for this target'))

        monitor.user_id = r.user.user_id
        monitor.state = Monitor.ST_ADDED
        monitor.user_state = Monitor.U_ST_NORMAL
        monitor.beat = beat if beat >= limits.min_beat(r.user) else limits.min_beat(r.user)
         
        default_email = r.session.query(Destination).filter_by(user=r.user, destination_name='Default Email').one()
        default_sms = r.session.query(Destination).filter_by(user=r.user, destination_name='Default SMS').one()
        
        umd_email = AlertDestination(monitor, default_email)
        umd_email.alert_destination_state = AlertDestination.ST_NEW
        umd_email.notify_down_on = 1
        umd_email.notify_up = 0
        
        umd_sms = AlertDestination(monitor, default_sms)
        umd_sms.alert_destination_state  = AlertDestination.ST_NEW
        umd_sms.notify_down_on = 1
        umd_sms.notify_up = 0

        r.session.save(monitor)
        r.session.save(umd_email)
        r.session.save(umd_sms)
        r.session.flush()
        
        r.hub.touchMonitor(monitor.monitor_id)
Beispiel #2
0
    def set_settings(self, r, name, beat, new_name):
        if new_name != name and new_name in r.user.monitors.keys():
            raise ValidationFailedException(dict(new_name='Check with name "%s" already exist' % new_name))

        if beat >= limits.min_beat(r.user):
            permitted_beat = beat
        else:
            permitted_beat = limits.min_beat(r.user)    
        monitor = r.user.monitors[name]
        monitor.beat = permitted_beat
        
        if new_name != name:
            monitor.name = new_name
            
        r.session.flush()
        r.hub.touchMonitor(monitor.monitor_id)
Beispiel #3
0
 def limits(self, r):
     max_monitors = limits.max_monitor_count(r.user)
     min_beat = limits.min_beat(r.user)
     sms_credits = r.user.sms_credits_plan + r.user.sms_credits_purchased
     allow_https = limits.is_https_allowed(r.user)
     return dict(max_monitors=max_monitors, 
                 min_beat=min_beat, 
                 sms_credits=sms_credits, 
                 sms_credis_warn=3,
                 allow_https=allow_https)