From 3b7ad40cd03eedd59fc78c565fce286e19d85258 Mon Sep 17 00:00:00 2001 From: Kevan Holdaway Date: Wed, 25 Oct 2017 13:11:31 -0400 Subject: [PATCH] Add new facts to elasticsearch model --- quipucords/api/es_receivers.py | 98 +++++++++++++++++++--- quipucords/api/fact_collection_receiver.py | 2 +- 2 files changed, 87 insertions(+), 13 deletions(-) diff --git a/quipucords/api/es_receivers.py b/quipucords/api/es_receivers.py index 9bee5baf1..978cac910 100644 --- a/quipucords/api/es_receivers.py +++ b/quipucords/api/es_receivers.py @@ -18,7 +18,12 @@ from django.dispatch import receiver from api.models import SystemFingerprint from elasticsearch_dsl.connections import connections -from elasticsearch_dsl import DocType, Date, Keyword, Index +from elasticsearch_dsl import (DocType, + Date, + Keyword, + Index, + Integer, + Boolean) from elasticsearch.exceptions import RequestError logger = logging.getLogger(__name__) # pylint: disable=invalid-name @@ -41,8 +46,25 @@ def index_fingerprint(sender, instance, **kwargs): """ # pylint: disable=unused-argument es_fingerprint = FingerPrintIndex( - fact_collection_id=instance.id, os_name=instance.os_name, - os_release=instance.os_release, os_version=instance.os_version, + fact_collection=instance.id, + connection_host=instance.connection_host, + connection_port=instance.connection_port, + connection_uuid=instance.connection_uuid, + cpu_count=instance.cpu_count, + cpu_core_per_socket=instance.cpu_core_per_socket, + cpu_siblings=instance.cpu_siblings, + cpu_hyperthreading=instance.cpu_hyperthreading, + cpu_socket_count=instance.cpu_socket_count, + cpu_core_count=instance.cpu_core_count, + system_creation_date=instance.system_creation_date, + infrastructure_type=instance.infrastructure_type, + os_name=instance.os_name, + os_version=instance.os_version, + os_release=instance.os_release, + virtualized_is_guest=instance.virtualized_is_guest, + virtualized_type=instance.virtualized_type, + virtualized_num_guests=instance.virtualized_num_guests, + virtualized_num_running_guests=instance.virtualized_num_running_guests, timestamp=int(round(time.time() * 1000))) try: @@ -60,6 +82,26 @@ class FingerPrintIndex(DocType): os_name = Keyword() os_release = Keyword() os_version = Keyword() + + connection_host = Keyword() + connection_port = Integer() + connection_uuid = Keyword() + + cpu_count = Integer() + cpu_core_per_socket = Integer() + cpu_siblings = Integer() + cpu_hyperthreading = Boolean() + cpu_socket_count = Integer() + cpu_core_count = Integer() + + system_creation_date = Date() + infrastructure_type = Keyword() + + virtualized_is_guest = Boolean() + virtualized_type = Keyword() + virtualized_num_guests = Integer() + virtualized_num_running_guests = Integer() + timestamp = Date() def __init__(self, *args, **kwargs): @@ -69,15 +111,47 @@ def __init__(self, *args, **kwargs): self.index.create() def __str__(self): - return '{' + 'id:{}, fact_collection:{}, ' \ - 'os_name:{}, os_release:{}, '\ - 'os_version:{}' \ - .format( - self.fact_collection_id, - self.os_name, - self.os_release, - self.os_version, - str(self.timestamp) + '}') + return '{' + \ + 'fact_collection_id:{}, '\ + 'connection_host:{}, '\ + 'connection_port:{}, '\ + 'connection_uuid:{}, '\ + 'cpu_count:{}, '\ + 'cpu_core_per_socket:{}, '\ + 'cpu_siblings:{}, '\ + 'cpu_hyperthreading:{}, '\ + 'cpu_socket_count:{}, '\ + 'cpu_core_count:{}, '\ + 'system_creation_date:{}, '\ + 'infrastructure_type:{}, '\ + 'os_name:{},, '\ + 'os_version:{},, '\ + 'os_release:{},, '\ + 'virtualized_is_guest:{}, '\ + 'virtualized_type:{}, '\ + 'virtualized_num_guests:{}, '\ + 'virtualized_num_running_guests:{}, '\ + 'timestamp:{}'\ + .format(self.fact_collection_id, + self.connection_host, + self.connection_port, + self.connection_uuid, + self.cpu_count, + self.cpu_core_per_socket, + self.cpu_siblings, + self.cpu_hyperthreading, + self.cpu_socket_count, + self.cpu_core_count, + self.system_creation_date, + self.infrastructure_type, + self.os_name, + self.os_version, + self.os_release, + self.virtualized_is_guest, + self.virtualized_type, + self.virtualized_num_guests, + self.virtualized_num_running_guests, + str(self.timestamp)) + '}' class Meta: """FingerPrintIndex Meta class.""" diff --git a/quipucords/api/fact_collection_receiver.py b/quipucords/api/fact_collection_receiver.py index f3d4d3275..e3ee16bc0 100644 --- a/quipucords/api/fact_collection_receiver.py +++ b/quipucords/api/fact_collection_receiver.py @@ -53,4 +53,4 @@ def process_fact_collection(sender, instance, **kwargs): else: logger.error('%s could not persist fingerprint. Fact: %s', __name__, fingerprint_dict) - logger.error(serializer.errors) + logger.error('Errors: %s', serializer.errors)