Add a new jsonprint filter, used in metrics, query
This commit is contained in:
@@ -18,7 +18,7 @@ from pypuppetdb import connect
|
|||||||
from puppetboard.forms import QueryForm
|
from puppetboard.forms import QueryForm
|
||||||
from puppetboard.utils import (
|
from puppetboard.utils import (
|
||||||
get_or_abort, yield_or_stop,
|
get_or_abort, yield_or_stop,
|
||||||
ten_reports,
|
ten_reports, jsonprint
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -27,6 +27,8 @@ app.config.from_object('puppetboard.default_settings')
|
|||||||
app.config.from_envvar('PUPPETBOARD_SETTINGS', silent=True)
|
app.config.from_envvar('PUPPETBOARD_SETTINGS', silent=True)
|
||||||
app.secret_key = os.urandom(24)
|
app.secret_key = os.urandom(24)
|
||||||
|
|
||||||
|
app.jinja_env.filters['jsonprint'] = jsonprint
|
||||||
|
|
||||||
puppetdb = connect(
|
puppetdb = connect(
|
||||||
api_version=3,
|
api_version=3,
|
||||||
host=app.config['PUPPETDB_HOST'],
|
host=app.config['PUPPETDB_HOST'],
|
||||||
|
|||||||
@@ -11,7 +11,11 @@
|
|||||||
{% for key,value in metric %}
|
{% for key,value in metric %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{key}}</td>
|
<td>{{key}}</td>
|
||||||
<td>{{value}}</td>
|
{% if value is mapping %}
|
||||||
|
<td><pre>{{value|jsonprint}}</pre></td>
|
||||||
|
{% else %}
|
||||||
|
<td>{{value}}</td>
|
||||||
|
{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -53,7 +53,7 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="span12">
|
<div class="span12">
|
||||||
<h2>Result</h2>
|
<h2>Result</h2>
|
||||||
<pre><code>{{ result|tojson|replace(", ", ",\n") }}</code></pre>
|
<pre><code>{{result|jsonprint}}</code></pre>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
from requests.exceptions import HTTPError, ConnectionError
|
from requests.exceptions import HTTPError, ConnectionError
|
||||||
from pypuppetdb.errors import EmptyResponseError
|
from pypuppetdb.errors import EmptyResponseError
|
||||||
|
|
||||||
from flask import abort
|
from flask import abort
|
||||||
|
|
||||||
|
def jsonprint(value):
|
||||||
|
return json.dumps(value, indent=2, separators=(',', ': ') )
|
||||||
|
|
||||||
|
|
||||||
def get_or_abort(func, *args, **kwargs):
|
def get_or_abort(func, *args, **kwargs):
|
||||||
"""Execute the function with its arguments and handle the possible
|
"""Execute the function with its arguments and handle the possible
|
||||||
|
|||||||
Reference in New Issue
Block a user