def get_by_id(self, message_id): # FIXME: add documentation # FIXME: add tests column_key = self.str_to_column_key(message_id) row_key = ymdhm_from_uuid1(column_key[0]) try: json_str = self._get_cf_logs().get(row_key, columns=[column_key])[column_key] except NotFoundException: return None return json.loads(json_str)
def get_by_id(self, message_id): # FIXME: add documentation # FIXME: add tests column_key = self.str_to_column_key(message_id) row_key = ymdhm_from_uuid1(column_key[0]) try: json_str = self._get_cf_logs().get(row_key, columns=[column_key ])[column_key] except NotFoundException: return None return json.loads(json_str)
def save_log(self, application, host, severity, timestamp, message, multi_message=False, multimessage_id=None): """ Saves a log message. Raises: - DaedalusException if any parameter isn't valid. Returns: - tuple with (row_key, column_key, multimessage_id) """ _check_application(application) _check_severity(severity) _check_host(host) _check_message(message) try: timestamp = float(timestamp) except: raise (DaedalusException( "The timestamp '{0}' couldn't be " "transformed to a float".format(timestamp))) assert multi_message in ( True, False, ) event_uuid = convert_time_to_uuid(timestamp, randomize=True) column_key = (event_uuid, host, application, severity) _id = ','.join(( event_uuid.get_hex(), host, application, severity, )) if not application in self._app_cache: self._app_cache[application] = True self._get_cf_metadata().insert('applications', {application: ''}) if not host in self._host_cache: self._host_cache[host] = True self._get_cf_metadata().insert('hosts', {host: ''}) row_key = ymdhm_from_uuid1(event_uuid) key_for_bitmap = int(row_key) if not key_for_bitmap in self._timestamp_bitmap_cache: self._timestamp_bitmap_cache[key_for_bitmap] = True self._get_cf_timestamp_bitmap().insert('timestamp_bitmap', {key_for_bitmap: ''}) message_dict = { 'application': application, 'host': host, 'severity': severity, 'timestamp': timestamp, '_id': _id, 'message': message, } if multi_message: # this message is part of a multi-message if multimessage_id: # The multi-message key was passed as parameter message_dict['multimessage_id'] = multimessage_id else: message_dict['multimessage_id'] = ','.join([row_key, _id]) self._get_cf_logs().insert(row_key, { column_key: json.dumps(message_dict), }) return (row_key, column_key, message_dict.get('multimessage_id', None))
def _get_bitmap_key_from_event_uuid(self, event_uuid): row_key = ymdhm_from_uuid1(event_uuid) key_for_bitmap = int(row_key) return key_for_bitmap
def save_log(self, application, host, severity, timestamp, message, multi_message=False, multimessage_id=None): """ Saves a log message. Raises: - DaedalusException if any parameter isn't valid. Returns: - tuple with (row_key, column_key, multimessage_id) """ _check_application(application) _check_severity(severity) _check_host(host) _check_message(message) try: timestamp = float(timestamp) except: raise(DaedalusException("The timestamp '{0}' couldn't be " "transformed to a float".format(timestamp))) assert multi_message in (True, False,) event_uuid = convert_time_to_uuid(timestamp, randomize=True) column_key = (event_uuid, host, application, severity) _id = ','.join((event_uuid.get_hex(), host, application, severity, )) if not application in self._app_cache: self._app_cache[application] = True self._get_cf_metadata().insert('applications', {application: ''}) if not host in self._host_cache: self._host_cache[host] = True self._get_cf_metadata().insert('hosts', {host: ''}) row_key = ymdhm_from_uuid1(event_uuid) key_for_bitmap = int(row_key) if not key_for_bitmap in self._timestamp_bitmap_cache: self._timestamp_bitmap_cache[key_for_bitmap] = True self._get_cf_timestamp_bitmap().insert('timestamp_bitmap', {key_for_bitmap: ''}) message_dict = { 'application': application, 'host': host, 'severity': severity, 'timestamp': timestamp, '_id': _id, 'message': message, } if multi_message: # this message is part of a multi-message if multimessage_id: # The multi-message key was passed as parameter message_dict['multimessage_id'] = multimessage_id else: message_dict['multimessage_id'] = ','.join([row_key, _id]) self._get_cf_logs().insert(row_key, { column_key: json.dumps(message_dict), }) return (row_key, column_key, message_dict.get('multimessage_id', None))