def to_internal_value(self, value): try: date_time = core_utils.timestamp_to_datetime(value) datetime_str = date_time.strftime(self.formats[0]) except ValueError: raise serializers.ValidationError( _('Value "{}" should be valid UNIX timestamp.').format(value)) return datetime_str
def process(self, event): if not self.email: logger.debug('Skipping processing of email hook (PK=%s) because email is not defined' % self.pk) return # Prevent mutations of event because otherwise subsequent hook processors would fail context = event.copy() subject = 'Notifications from Waldur' context['timestamp'] = timestamp_to_datetime(event['timestamp']) text_message = context['message'] html_message = render_to_string('logging/email.html', {'events': [context]}) logger.debug('Submitting email hook to %s, payload: %s', self.email, context) send_mail(subject, text_message, settings.DEFAULT_FROM_EMAIL, [self.email], html_message=html_message)
def _get_sla_field_value(self, custom_field_values): sla_field_name = settings.WALDUR_SUPPORT.get('ISSUE', {}).get('sla_field', None) for field in custom_field_values: if isinstance(field, dict): name = field.get('name', None) if name and name == sla_field_name: ongoing_cycle = field.get('ongoingCycle', {}) breach_time = ongoing_cycle.get('breachTime', {}) epoch_milliseconds = breach_time.get('epochMillis', None) if epoch_milliseconds: return core_utils.timestamp_to_datetime(epoch_milliseconds / 1000.0) return None
def _parse_trigger(self, backend_trigger, backend_events=None, trigger_hosts=None): trigger = {} for field in django_settings.WALDUR_ZABBIX['TRIGGER_FIELDS']: trigger[field[0]] = backend_trigger[field[1]] trigger['changed'] = timestamp_to_datetime( backend_trigger['lastchange']) trigger['hosts'] = [] for host in backend_trigger['hosts']: host_id = host['hostid'] if trigger_hosts is not None: host_name = filter(lambda h: h['hostid'] == host_id, trigger_hosts) if host_name: host_name = host_name[0]['host'] else: host_name = '' else: host_name = None trigger['hosts'].append({'id': host_id, 'name': host_name}) trigger['event_count'] = None if backend_events is not None: events = filter(lambda e: e['objectid'] == trigger['backend_id'], backend_events) trigger[ 'event_count'] = 0 if not events else events[0]['rowscount'] return trigger
def to_internal_value(self, value): try: return utils.timestamp_to_datetime(value) except ValueError: raise serializers.ValidationError( _('Value "%s" should be valid UNIX timestamp.') % value)