Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Commit

Permalink
Link to agent log on reports view
Browse files Browse the repository at this point in the history
  • Loading branch information
propyless committed Sep 19, 2015
1 parent dcad29c commit 71742c2
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ PuppetDB resource and Fileserver. If both files are available you will be
able to get a diff between the files.
![Node Report Events View](screenshots/pp_node_report_events.png)

## Nodes Report Agent Log
View the puppet agents console log.
![Node Report Events View](screenshots/pp_node_report_agent_log.png)

## Node Report Events Execution Times
This graph shows the 10 highest execution times for the puppet run.
![Node Report Events Execution Times](screenshots/pp_report_events_execution_times.png)
Expand Down
8 changes: 8 additions & 0 deletions README_API.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@ Suitable for scripting if you want some kind of monitoring to check if more than
### Input parameters
* GET request
* Takes no input parameters.


## /pano/api/reports/\<report_hash_id\>/agent_log
JSON Response contain logs for the given report hash id if it exists.

### Input parameters
* GET request
* Takes no input parameters.
165 changes: 165 additions & 0 deletions pano/templates/pano/report_agent_logs.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
{% extends "pano/base.html" %}

{% load puppetdb_extras %}
{% load common %}
{% load static %}

{% block head %}
<script src="{% static 'pano/js/bootbox.min.js' %}"></script>
<script>
$(document).ready(function () {
get_report();
});
$(document).on({
ajaxStart: function () {
bootbox.dialog({
title: "Loading...",
message: "Fetching data from PuppetDB.",
show: true,
backdrop: false,
closeButton: true,
animate: false
});
},
ajaxStop: function () {
bootbox.hideAll()
}
});
</script>
<style>
.bs-callout {
padding: 5px;
margin: 7px 0;
border: 1px solid #eee;
border-left-width: 5px;
border-radius: 3px;
}

.bs-callout h4 {
margin-top: 0;
margin-bottom: 5px;
}

.bs-callout p:last-child {
margin-bottom: 0;
}

.bs-callout code {
border-radius: 3px;
}

.bs-callout + .bs-callout {
margin-top: -5px;
}

.bs-callout-default {
border-left-color: #777;
}

.bs-callout-default h4 {
color: #777;
}

.bs-callout-primary {
border-left-color: #428bca;
}

.bs-callout-primary h4 {
color: #428bca;
}

.bs-callout-success {
border-left-color: #5cb85c;
}

.bs-callout-success h4 {
color: #5cb85c;
}

.bs-callout-danger {
border-left-color: #d9534f;
}

.bs-callout-danger h4 {
color: #d9534f;
}

.bs-callout-warning {
border-left-color: #f0ad4e;
}

.bs-callout-warning h4 {
color: #f0ad4e;
}

.bs-callout-info {
border-left-color: #5bc0de;
}

.bs-callout-info h4 {
color: #5bc0de;
}
</style>
{% endblock %}

{% block content %}
<script>
function get_report(obj) {
var backgroundTask = $.Deferred();
var url = '/pano/api/reports/{{ report_hash }}/agent_log';
if ($(obj).attr('href')) {
var params = $(obj).attr('href');
url = url + params;
}
$.get(url, function (json) {
var response = $(jQuery(json));
var reports = response[0]['agent_log'];
var report_data = '';
if (!reports) {
report_data = '<div class="alert alert-danger" role="alert">Logs could not be retrieved for {{ certname }} with hash {{ report_hash }}</div>';
}
else {
reports.forEach(function (report) {
var color = 'muted'; // Default colour if none of below match..
if (report['level'] === 'info') {
color = 'success'
}
else if (report['level'] === 'warning') {
color = 'warning'
}
else if (report['level'] === 'err') {
color = 'danger'
}
else if (report['level'] === 'notice') {
color = 'muted'
}
report_data += '<div class="bs-callout bs-callout-' + color + '"><samp class="text-' + color +
'">' + report['level'] + ': ' + report['source'] + ': '
+ report['message'] + '</samp></div>'
});
}
$("#agent_logs").html(report_data);
})
.fail(function () {
var data = '<div class="bs-callout bs-callout-danger>Could not connect to PuppetDB.</div>';
$("#agent_logs").html(data);
});
backgroundTask.resolve();
return backgroundTask;
}
</script>
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h1 class="panel-title">
Puppet Agent Report for <strong>{{ certname }}</strong> with hash <strong>{{ report_hash }}</strong>
</h1>
</div>
<div class="panel-body" id="agent_logs">
</div>
</div>
</div>
</div>

{% endblock %}
2 changes: 2 additions & 0 deletions pano/templates/pano/reports.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
else if (report['report_status'] == 'failed') {
report_data += '<span class="glyphicon glyphicon-remove" style="color: #d9534f"></span>';
}
report_data += '<a href="../../events/{{ certname }}' + '/' + report['hash'] + '"><strong>[A]</strong></a>';

if (report['events_successes'] > 0 || report['events_noops'] > 0 || report['events_failures'] > 0 || report['events_skipped'] > 0) {
report_data += '<a href="../../events/' + report['hash'] + '?report_timestamp=' + report['start_time'] + '">' + report['hash'] + '</a></td>';
}
Expand Down
5 changes: 3 additions & 2 deletions pano/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pano.views.nodes import nodes
from pano.views.report_events import detailed_events
from pano.views.reports import reports
from pano.views.report_agent_logs import agent_logs
from pano.views.splash import splash
from pano.views.radiator import radiator
from pano.views.api.node_data import nodes_json
Expand All @@ -26,8 +27,8 @@
url(r'^filebucket/$', filebucket, name='filebucket'),
url(r'^nodes/$', nodes, name='nodes'),
url(r'^reports/(?P<certname>[\w\.-]+)/$', reports, name='reports'),
url(r'^events/(?P<hashid>[\w\.-]+)/$', detailed_events,
name='events'),
url(r'^events/(?P<hashid>[\w\.-]+)/$', detailed_events, name='events'),
url(r'^events/(?P<certname>[\w\.-]+)/(?P<report_hash>[\w]+)/$', agent_logs, name='agent_logs'),
url(r'^analytics/$', analytics, name='analytics'),
url(r'^eventanalytics/$', event_analytics, name='event_analytics'),
url(r'^eventanalytics/(?P<view>[\w]+)/$', event_analytics, name='event_analytics'),
Expand Down
27 changes: 27 additions & 0 deletions pano/views/report_agent_logs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
__author__ = 'etaklar'
from django.contrib.auth.decorators import login_required
from django.shortcuts import redirect, render
from django.views.decorators.cache import cache_page
from pano.settings import CACHE_TIME
from pano.puppetdb.puppetdb import set_server
from pano.settings import AVAILABLE_SOURCES
import pytz


@login_required
@cache_page(CACHE_TIME * 60) # Cache for cache_time multiplied 60 because the report will never change...
def agent_logs(request, certname=None, report_hash=None):
context = {'timezones': pytz.common_timezones,
'SOURCES': AVAILABLE_SOURCES}
if request.method == 'GET':
if 'source' in request.GET:
source = request.GET.get('source')
set_server(request, source)
if request.method == 'POST':
request.session['django_timezone'] = request.POST['timezone']
return redirect(request.POST['return_url'])

context['certname'] = certname
context['report_hash'] = report_hash

return render(request, 'pano/report_agent_logs.html', context)
Binary file added screenshots/pp_node_report_agent_log.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 71742c2

Please sign in to comment.