Merge pull request #204 from corey-hammerton/pypuppetdb-0.2.1
Using new Node and Catalog fields available in pypuppetdb 0.2.1 With the latest_report_hash field available on the Node object the report_latest can be partially deprecated. Will hopefully be removed in the next major/minor release.
This commit is contained in:
@@ -516,26 +516,44 @@ def report_latest(env, node_name):
|
||||
envs = environments()
|
||||
check_env(env, envs)
|
||||
|
||||
if env == '*':
|
||||
node_query = '["=", "certname", "{0}"]'.format(node_name)
|
||||
else:
|
||||
node_query = '["and",' \
|
||||
'["=", "report_environment", "{0}"],' \
|
||||
'["=", "certname", "{1}"]]'.format(env, node_name)
|
||||
|
||||
try:
|
||||
node = next(get_or_abort(puppetdb.nodes,
|
||||
query=node_query,
|
||||
with_status=True))
|
||||
except StopIteration:
|
||||
abort(404)
|
||||
|
||||
if node.latest_report_hash is not None:
|
||||
hash_ = node.latest_report_hash
|
||||
else:
|
||||
if env == '*':
|
||||
query='["and",' \
|
||||
'["=", "certname", "{0}"],' \
|
||||
'["=", "latest_report?", true]]'.format(node_name)
|
||||
'["=", "latest_report?", true]]'.format(node.name)
|
||||
else:
|
||||
query='["and",' \
|
||||
'["=", "environment", "{0}"],' \
|
||||
'["=", "certname", "{1}"],' \
|
||||
'["=", "latest_report?", true]]'.format(
|
||||
env,
|
||||
node_name)
|
||||
node.name)
|
||||
|
||||
reports = get_or_abort(puppetdb.reports, query=query)
|
||||
try:
|
||||
report = next(reports)
|
||||
hash_ = report.hash_
|
||||
except StopIteration:
|
||||
abort(404)
|
||||
|
||||
return redirect(
|
||||
url_for('report', env=env, node_name=node_name, report_id=report.hash_))
|
||||
url_for('report', env=env, node_name=node_name, report_id=hash_))
|
||||
|
||||
|
||||
@app.route('/report/<node_name>/<report_id>', defaults={'env': app.config['DEFAULT_ENVIRONMENT']})
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
<th>Hostname</th>
|
||||
<th>Version</th>
|
||||
<th>Transaction UUID</th>
|
||||
<th>Code ID</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -17,6 +18,7 @@
|
||||
<td><a href="{{url_for('node', env=current_env, node_name=catalog.node)}}">{{catalog.node}}</a></td>
|
||||
<td>{{catalog.version}}</td>
|
||||
<td>{{catalog.transaction_uuid}}</td>
|
||||
<td>{{catalog.code_id}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -79,14 +79,22 @@
|
||||
{% if node.status != 'unchanged' %}
|
||||
<tr>
|
||||
<td>
|
||||
{% if node.latest_report_hash %}
|
||||
{{macros.status_counts(status=node.status, node_name=node.name, events=node.events, unreported_time=node.unreported_time, current_env=current_env, report_hash=node.latest_report_hash)}}
|
||||
{% else %}
|
||||
{{macros.status_counts(status=node.status, node_name=node.name, events=node.events, unreported_time=node.unreported_time, current_env=current_env)}}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
<a href="{{url_for('node', env=current_env, node_name=node.name)}}">{{ node.name }}</a>
|
||||
</td>
|
||||
<td>
|
||||
{% if node.report_timestamp %}
|
||||
{% if node.latest_report_hash %}
|
||||
<a href="{{url_for('report', env=current_env, node_name=node.name, report_id=node.latest_report_hash)}}" rel='utctimestamp'>{{ node.report_timestamp }}</a>
|
||||
{% else %}
|
||||
<a href="{{url_for('report_latest', env=current_env, node_name=node.name)}}" rel='utctimestamp'>{{ node.report_timestamp }}</a>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<i class="large ban circle icon"></i>
|
||||
{% endif %}
|
||||
|
||||
@@ -18,13 +18,21 @@
|
||||
{% for node in nodes %}
|
||||
<tr>
|
||||
<td>
|
||||
{% if node.latest_report_hash %}
|
||||
{{macros.status_counts(status=node.status, node_name=node.name, events=node.events, unreported_time=node.unreported_time, current_env=current_env, report_hash=node.latest_report_hash)}}
|
||||
{% else %}
|
||||
{{macros.status_counts(status=node.status, node_name=node.name, events=node.events, unreported_time=node.unreported_time, current_env=current_env)}}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td><a href="{{url_for('node', env=current_env, node_name=node.name)}}">{{node.name}}</a></td>
|
||||
<td><a rel="utctimestamp" href="{{url_for('catalog_node', env=current_env, node_name=node.name)}}">{{node.catalog_timestamp}}</a></td>
|
||||
<td>
|
||||
{% if node.report_timestamp %}
|
||||
{% if node.latest_report_hash %}
|
||||
<a href="{{url_for('report', env=current_env, node_name=node.name, report_id=node.latest_report_hash)}}" rel='utctimestamp'>{{ node.report_timestamp }}</a>
|
||||
{% else %}
|
||||
<a href="{{url_for('report_latest', env=current_env, node_name=node.name)}}" rel='utctimestamp'>{{ node.report_timestamp }}</a>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<i class="large ban circle icon"></i>
|
||||
{% endif %}
|
||||
|
||||
Reference in New Issue
Block a user