Пример #1
0
 def post_one(self, req, key):
     """ Handle a HTTP POST request for a specific key. """
     if not key in req.system:
         raise exc.HTTPNotFound("No such key : '" + key + "'")
     req.system[key] = req.POST['value']
     meta.commit()
     return status_ok()
Пример #2
0
    def service_GET(self, req):
        """ Handle GET requests """
        # pylint: disable=unused-argument
        config = [
            SupportCaseCategoryOption('problem:category'),
            SupportCaseImpactOption('problem:impact'),
            SupportCaseLangOption('contact:language'),
            SupportCaseTzOption('contact:timezone'),
            SupportCaseProductOption('environment:product'),
            SupportCaseLangOption('environment:language'),
            SupportCaseVersionOption('environment:version'),
            SupportCaseOSOption('environment:operating-system'),
            SupportCaseDataSourceOption('environment:data-source')
        ]
        data = {'config': [option.default() for option in config]}

        profile = req.environ['REMOTE_USER']
        if profile.userid > 0:
            if profile.friendly_name:
                data['contact:name'] = profile.friendly_name
            if profile.email:
                data['contact:email'] = profile.email

        company_name = req.system[SystemKeys.COMPANY_NAME]
        if company_name:
            data['contact:company'] = company_name
        meta.commit()

        return data
Пример #3
0
 def service_POST(self, req):
     req.system[SystemKeys.ZIPLOG_AUTO_RETAIN_COUNT] = \
                         req.POST['ziplog-auto-retain-count']
     req.system[SystemKeys.ZIPLOG_USER_RETAIN_COUNT] = \
                         req.POST['ziplog-user-retain-count']
     meta.commit()
     return {}
Пример #4
0
 def service_POST(self, req):
     req.system[SystemKeys.BACKUP_AUTO_RETAIN_COUNT] = \
                                     req.POST['backup-auto-retain-count']
     req.system[SystemKeys.BACKUP_USER_RETAIN_COUNT] = \
                                     req.POST['backup-user-retain-count']
     meta.commit()
     return {}
Пример #5
0
    def cloud_save(self, req):
        # pylint: disable=invalid-name
        bucket = self.url_to_bucket(req.POST['url'])
        if not bucket:
            raise exc.HTTPBadRequest()

        entry = self._get_by_type(req.envid)
        # The name and the bucket are currently the same.
        entry.name = bucket
        entry.bucket = bucket
        entry.access_key = req.POST['access-key']
        entry.secret = aes_encrypt(req.POST['secret-key'])

        meta.commit()
        # commit first to have entry.cloudid set which is saved into
        # the system table next.
        req.system[self.KEY] = entry.cloudid

        backup_dest_type = FileManager.STORAGE_TYPE_CLOUD
        req.system[SystemKeys.BACKUP_DEST_TYPE] = backup_dest_type
        req.system[SystemKeys.BACKUP_DEST_ID] = entry.cloudid

        # Commit for system table changes
        meta.commit()
        return self._todict(entry)
Пример #6
0
 def service_proxy(self, req):
     """Save a proxy configuration value to the system table."""
     value = req.params['value']
     if value:
         req.system[SystemKeys.PROXY_HTTPS] = value
     else:
         del req.system[SystemKeys.PROXY_HTTPS]
     meta.commit()
     return {'status': 'OK'}
Пример #7
0
    def _store_info(self, req):
        """ Cache information from this request that will be used later. """
        phone = req.params.get('contact:phone')
        if phone:
            profile = req.environ['REMOTE_USER']
            if profile.userid > 0:
                profile.phone = phone

        company_name = req.params.get('contact:company')
        if company_name:
            req.system[SystemKeys.COMPANY_NAME] = company_name
        else:
            del req.system[SystemKeys.COMPANY_NAME]
        meta.commit()
Пример #8
0
    def service_POST(self, req):

        req.system[SystemKeys.ALERTS_PUBLISHER_ENABLED] = \
                            req.POST['alert-publishers']
        req.system[SystemKeys.ALERTS_ADMIN_ENABLED] = req.POST['alert-admins']

        if str2bool(req.POST['alert-publishers']) or \
                  str2bool(req.POST['alert-admins']):
            req.system[SystemKeys.EMAIL_SPIKE_DISABLED_ALERTS] = 'no'
            # does a session.commit()
            EmailLimitEntry.remove_all(req.envid)
        else:
            meta.commit()
        return {}
Пример #9
0
 def service_POST(self, req):
     """ Handle a HTTP POST request. """
     environ_key = ENVIRON_PREFIX + 'key'
     if environ_key in req.environ:
         return self.post_one(req, req.environ[environ_key])
     keys = []
     for key in req.POST:
         if not key in req.system:
             raise exc.HTTPBadRequest("Invalid system key : '" + key + "'")
         keys.append(key)
     if not keys:
         raise exc.HTTPBadRequest("No system keys specified.")
     for key in keys:
         req.system[key] = req.POST[key]
     meta.commit()
     return status_ok()
Пример #10
0
    def service_POST(self, req):
        for key in (SystemKeys.WORKBOOK_RETAIN_COUNT,
                    SystemKeys.DATASOURCE_RETAIN_COUNT):
            req.system[key] = req.POST[key]

        key = 'extract-retain-count'
        req.system[SystemKeys.EXTRACT_RETAIN_COUNT] = req.POST[key]

        cred = self.get_cred(req.envid, self.PRIMARY_KEY)
        if not cred:
            cred = CredentialEntry(envid=req.envid, key=self.PRIMARY_KEY)
            meta.Session.add(cred)

        cred.user = req.POST['archive-username']
        cred.setpasswd(req.POST['archive-password'])

        meta.commit()
        return {}
Пример #11
0
    def email_limit_reached(self, event_entry, eventid):
        """Keep track of how many emails have been sent during the last
           email-lookback-minutes period and check to see if
           email-max-count have already been sent.  Return:
                count-of-emails-sent-recently:  if email_limit reached
                                                reached (don't send more
                                                emails).
                False if email-limit hasn't been reached (keep sending emails).
        """

        logger.debug("email_limit_reached checking: event %s, eventid %s\n",
                     event_entry.key, eventid)

        # We limit only ERROR events.
        if event_entry.level != 'E' or \
            event_entry.key in [EventControl.EMAIL_TEST,
                                                    EventControl.EMAIL_SPIKE]:
            # These events can always be emailed and don't count against
            # the maximum.
            return False

        self._log_email(eventid)
        self._prune()  # Keep only the last email-looback-minutes rows

        emails_sent_recently = self._recent_count()
        email_lookback_minutes = self.system[SystemKeys.EMAIL_LOOKBACK_MINUTES]
        logger.debug(
            "email_limit: sent %d error emails in the last "
            "%d minutes.", emails_sent_recently, email_lookback_minutes)

        email_max_count = self.system[SystemKeys.EMAIL_MAX_COUNT]
        if emails_sent_recently > email_max_count:
            # Don't sent this email alert
            # send an alert that we're disabling email alerts
            self._eventit()
            # Disable email alerts
            self.system[SystemKeys.ALERTS_ADMIN_ENABLED] = False
            self.system[SystemKeys.ALERTS_PUBLISHER_ENABLED] = False
            self.system[SystemKeys.EMAIL_SPIKE_DISABLED_ALERTS] = True
            meta.commit()
            return emails_sent_recently

        # Send this email alert
        return False
Пример #12
0
    def _save_config(self, req, data):
        """Save the configuration to the system table."""
        req.system[SystemKeys.MAIL_SERVER_TYPE] = data['mail-server-type']

        if data['mail-server-type'] != MailServerType.NONE:
            req.system[SystemKeys.FROM_EMAIL] = data['from-email']
            req.system[SystemKeys.MAIL_DOMAIN] = data['mail-domain']

        if data['mail-server-type'] == MailServerType.RELAY:
            req.system[SystemKeys.MAIL_SMTP_SERVER] = data['smtp-server']
            req.system[SystemKeys.MAIL_SMTP_PORT] = data['smtp-port']
            req.system[SystemKeys.MAIL_USERNAME] = data['smtp-username']
            req.system[SystemKeys.MAIL_PASSWORD] = data['smtp-password']
        else:
            del req.system[SystemKeys.MAIL_SMTP_SERVER]
            del req.system[SystemKeys.MAIL_SMTP_PORT]
            del req.system[SystemKeys.MAIL_USERNAME]
            del req.system[SystemKeys.MAIL_PASSWORD]
        meta.commit()
Пример #13
0
    def service_POST(self, req):
        """
        Saves the settings for the TOTAL load thresholds
        :param req:
        :return: success
        """
        # pylint: disable=unused-argument
        req.system[SystemKeys.WATERMARK_LOW] = req.POST['disk-watermark-low']
        req.system[SystemKeys.WATERMARK_HIGH] = req.POST['disk-watermark-high']

        req.system[SystemKeys.CPU_LOAD_WARN] = req.POST['cpu-load-warn']
        req.system[SystemKeys.CPU_LOAD_ERROR] = req.POST['cpu-load-error']

        req.system[SystemKeys.CPU_PERIOD_WARN] = req.POST['cpu-period-warn']
        req.system[SystemKeys.CPU_PERIOD_ERROR] = req.POST['cpu-period-error']

        req.system[SystemKeys.HTTP_LOAD_WARN] = req.POST['http-load-warn']
        req.system[SystemKeys.HTTP_LOAD_ERROR] = req.POST['http-load-error']

        meta.commit()
        return {}
Пример #14
0
 def save(self, key, value):
     """ Update the database and commit """
     self[key] = value
     meta.commit()
Пример #15
0
 def cloud_remove(self, req):
     # 'action' is just sanity check, its not used.
     del req.system[self.KEY]
     meta.commit()
     return {}