Skip to content

Commit

Permalink
Add new facts to elasticsearch model
Browse files Browse the repository at this point in the history
  • Loading branch information
kholdaway committed Oct 25, 2017
1 parent f0663e1 commit 3b7ad40
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 13 deletions.
98 changes: 86 additions & 12 deletions quipucords/api/es_receivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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):
Expand All @@ -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."""
Expand Down
2 changes: 1 addition & 1 deletion quipucords/api/fact_collection_receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 3b7ad40

Please sign in to comment.