summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTim Laszlo <tim.laszlo@gmail.com>2012-06-14 10:20:12 -0500
committerTim Laszlo <tim.laszlo@gmail.com>2012-06-14 10:21:32 -0500
commit3f3d2138aca930c59a2139f6ff2a5405c2449fe5 (patch)
treeae138e8a9c69d2dd1cfdb8cbb3b059b7a19cf9e7 /src
parent772ea973da6b425e9f2336ed64cb2fd1081b3256 (diff)
downloadbcfg2-3f3d2138aca930c59a2139f6ff2a5405c2449fe5.tar.gz
bcfg2-3f3d2138aca930c59a2139f6ff2a5405c2449fe5.tar.bz2
bcfg2-3f3d2138aca930c59a2139f6ff2a5405c2449fe5.zip
DBStats: Start loading good entries into the db
Diffstat (limited to 'src')
-rwxr-xr-xsrc/lib/Bcfg2/Server/Reports/importscript.py70
-rw-r--r--src/lib/Bcfg2/Server/Reports/reports/models.py2
-rw-r--r--src/lib/Bcfg2/Server/Reports/reports/views.py8
3 files changed, 51 insertions, 29 deletions
diff --git a/src/lib/Bcfg2/Server/Reports/importscript.py b/src/lib/Bcfg2/Server/Reports/importscript.py
index 2aade17b3..d1f47b1f4 100755
--- a/src/lib/Bcfg2/Server/Reports/importscript.py
+++ b/src/lib/Bcfg2/Server/Reports/importscript.py
@@ -88,6 +88,24 @@ def build_reason_kwargs(r_ent, encoding, logger):
is_sensitive=sensitive_file,
unpruned=unpruned_entries)
+def _fetch_reason(elem, kargs):
+ try:
+ rr = None
+ try:
+ rr = Reason.objects.filter(**kargs)[0]
+ except IndexError:
+ rr = Reason(**kargs)
+ rr.save()
+ if vlevel > 0:
+ logger.info("Created reason: %s" % rr.id)
+ except Exception:
+ ex = sys.exc_info()[1]
+ logger.error("Failed to create reason for %s: %s" % (elem.get('name'), ex))
+ rr = Reason(current_exists=elem.get('current_exists',
+ default="True").capitalize() == "True")
+ rr.save()
+ return rr
+
def load_stats(sdata, encoding, vlevel, logger, quick=False, location=''):
for node in sdata.findall('Node'):
@@ -156,46 +174,44 @@ def load_stat(cobj, statistics, encoding, vlevel, logger, quick, location):
(client_name, traceback.format_exc().splitlines()[-1]))
- counter_fields = {TYPE_CHOICES[0]: 0,
- TYPE_CHOICES[1]: 0,
- TYPE_CHOICES[2]: 0}
- pattern = [('Bad/*', TYPE_CHOICES[0]),
- ('Extra/*', TYPE_CHOICES[2]),
- ('Modified/*', TYPE_CHOICES[1])]
+ counter_fields = {TYPE_BAD: 0,
+ TYPE_MODIFIED: 0,
+ TYPE_EXTRA: 0}
+ pattern = [('Bad/*', TYPE_BAD),
+ ('Extra/*', TYPE_EXTRA),
+ ('Modified/*', TYPE_MODIFIED)]
for (xpath, type) in pattern:
for x in statistics.findall(xpath):
counter_fields[type] = counter_fields[type] + 1
- kargs = build_reason_kwargs(x, encoding, logger)
-
- try:
- rr = None
- try:
- rr = Reason.objects.filter(**kargs)[0]
- except IndexError:
- rr = Reason(**kargs)
- rr.save()
- if vlevel > 0:
- logger.info("Created reason: %s" % rr.id)
- except Exception:
- ex = sys.exc_info()[1]
- logger.error("Failed to create reason for %s: %s" % (x.get('name'), ex))
- rr = Reason(current_exists=x.get('current_exists',
- default="True").capitalize() == "True")
- rr.save()
+ rr = _fetch_reason(x, build_reason_kwargs(x, encoding, logger))
entry, created = Entries.objects.get_or_create(\
name=x.get('name'), kind=x.tag)
Entries_interactions(entry=entry, reason=rr,
interaction=current_interaction,
- type=type[0]).save()
+ type=type).save()
if vlevel > 0:
logger.info("%s interaction created with reason id %s and entry %s" % (xpath, rr.id, entry.id))
+ # add good entries
+ good_reason = None
+ for x in statistics.findall('Good/*'):
+ if good_reason == None:
+ # Do this once. Really need to fix Reasons...
+ good_reason = _fetch_reason(x, build_reason_kwargs(x, encoding, logger))
+ entry, created = Entries.objects.get_or_create(\
+ name=x.get('name'), kind=x.tag)
+ Entries_interactions(entry=entry, reason=good_reason,
+ interaction=current_interaction,
+ type=TYPE_GOOD).save()
+ if vlevel > 0:
+ logger.info("%s interaction created with reason id %s and entry %s" % (xpath, good_reason.id, entry.id))
+
# Update interaction counters
- current_interaction.bad_entries = counter_fields[TYPE_CHOICES[0]]
- current_interaction.modified_entries = counter_fields[TYPE_CHOICES[1]]
- current_interaction.extra_entries = counter_fields[TYPE_CHOICES[2]]
+ current_interaction.bad_entries = counter_fields[TYPE_BAD]
+ current_interaction.modified_entries = counter_fields[TYPE_MODIFIED]
+ current_interaction.extra_entries = counter_fields[TYPE_EXTRA]
current_interaction.save()
mperfs = []
diff --git a/src/lib/Bcfg2/Server/Reports/reports/models.py b/src/lib/Bcfg2/Server/Reports/reports/models.py
index 750add34d..3bce17a30 100644
--- a/src/lib/Bcfg2/Server/Reports/reports/models.py
+++ b/src/lib/Bcfg2/Server/Reports/reports/models.py
@@ -23,11 +23,13 @@ KIND_CHOICES = (
('Path', 'symlink'),
('Service', 'Service'),
)
+TYPE_GOOD = 0
TYPE_BAD = 1
TYPE_MODIFIED = 2
TYPE_EXTRA = 3
TYPE_CHOICES = (
+ (TYPE_GOOD, 'Good'),
(TYPE_BAD, 'Bad'),
(TYPE_MODIFIED, 'Modified'),
(TYPE_EXTRA, 'Extra'),
diff --git a/src/lib/Bcfg2/Server/Reports/reports/views.py b/src/lib/Bcfg2/Server/Reports/reports/views.py
index 2e2c361fe..439d01c7c 100644
--- a/src/lib/Bcfg2/Server/Reports/reports/views.py
+++ b/src/lib/Bcfg2/Server/Reports/reports/views.py
@@ -231,9 +231,11 @@ def common_problems(request, timestamp=None, threshold=None):
threshold = 10
c_intr = Interaction.objects.get_interaction_per_client_ids(timestamp)
- data_list = { 1: {}, 2: {}, 3: {}}
+ data_list = {}
+ [data_list.__setitem__(t_id, {}) \
+ for t_id, t_label in TYPE_CHOICES if t_id != TYPE_GOOD]
ldata = list(Entries_interactions.objects.filter(
- interaction__in=c_intr).values())
+ interaction__in=c_intr).exclude(type=TYPE_GOOD).values())
entry_ids = set([x['entry_id'] for x in ldata])
reason_ids = set([x['reason_id'] for x in ldata])
@@ -250,6 +252,8 @@ def common_problems(request, timestamp=None, threshold=None):
lists = []
for type, type_name in TYPE_CHOICES:
+ if type == TYPE_GOOD:
+ continue
lists.append([type_name.lower(), [(entries[e[0][0]], reasons[e[0][1]], e[1])
for e in sorted(data_list[type].items(), key=lambda x: len(x[1]), reverse=True)
if len(e[1]) > threshold]])