Support for PuppetDB 3.x on all environments
Mbeans use type=default in puppetdb 3x, type was removed in 4x.
This commit is contained in:
@@ -21,7 +21,7 @@ from pypuppetdb.QueryBuilder import *
|
|||||||
|
|
||||||
from puppetboard.forms import (CatalogForm, QueryForm)
|
from puppetboard.forms import (CatalogForm, QueryForm)
|
||||||
from puppetboard.utils import (
|
from puppetboard.utils import (
|
||||||
get_or_abort, yield_or_stop,
|
get_or_abort, yield_or_stop, get_db_version,
|
||||||
jsonprint, prettyprint
|
jsonprint, prettyprint
|
||||||
)
|
)
|
||||||
from puppetboard.dailychart import get_daily_reports_chart
|
from puppetboard.dailychart import get_daily_reports_chart
|
||||||
@@ -173,15 +173,23 @@ def index(env):
|
|||||||
query = app.config['OVERVIEW_FILTER']
|
query = app.config['OVERVIEW_FILTER']
|
||||||
|
|
||||||
prefix = 'puppetlabs.puppetdb.population'
|
prefix = 'puppetlabs.puppetdb.population'
|
||||||
|
query_type = ''
|
||||||
|
|
||||||
|
# Puppet DB version changed the query format from 3.2.0
|
||||||
|
# to 4.0 when querying mbeans
|
||||||
|
if get_db_version(puppetdb) < (4, 0, 0):
|
||||||
|
query_type = 'type=default,'
|
||||||
|
|
||||||
num_nodes = get_or_abort(
|
num_nodes = get_or_abort(
|
||||||
puppetdb.metric,
|
puppetdb.metric,
|
||||||
"{0}{1}".format(prefix, ':name=num-nodes'))
|
"{0}{1}".format(prefix, ':%sname=num-nodes' % query_type))
|
||||||
num_resources = get_or_abort(
|
num_resources = get_or_abort(
|
||||||
puppetdb.metric,
|
puppetdb.metric,
|
||||||
"{0}{1}".format(prefix, ':name=num-resources'))
|
"{0}{1}".format(prefix, ':%sname=num-resources' % query_type))
|
||||||
avg_resources_node = get_or_abort(
|
avg_resources_node = get_or_abort(
|
||||||
puppetdb.metric,
|
puppetdb.metric,
|
||||||
"{0}{1}".format(prefix, ':name=avg-resources-per-node'))
|
"{0}{1}".format(prefix,
|
||||||
|
':%sname=avg-resources-per-node' % query_type))
|
||||||
metrics['num_nodes'] = num_nodes['Value']
|
metrics['num_nodes'] = num_nodes['Value']
|
||||||
metrics['num_resources'] = num_resources['Value']
|
metrics['num_resources'] = num_resources['Value']
|
||||||
metrics['avg_resources_node'] = "{0:10.0f}".format(
|
metrics['avg_resources_node'] = "{0:10.0f}".format(
|
||||||
@@ -971,10 +979,13 @@ def radiator(env):
|
|||||||
check_env(env, envs)
|
check_env(env, envs)
|
||||||
|
|
||||||
if env == '*':
|
if env == '*':
|
||||||
|
query_type = ''
|
||||||
|
if get_db_version(puppetdb) < (4, 0, 0):
|
||||||
|
query_type = 'type=default,'
|
||||||
query = None
|
query = None
|
||||||
metrics = get_or_abort(
|
metrics = get_or_abort(
|
||||||
puppetdb.metric,
|
puppetdb.metric,
|
||||||
'puppetlabs.puppetdb.population:name=num-nodes')
|
'puppetlabs.puppetdb.population:%sname=num-nodes' % query_type)
|
||||||
num_nodes = metrics['Value']
|
num_nodes = metrics['Value']
|
||||||
else:
|
else:
|
||||||
query = AndOperator()
|
query = AndOperator()
|
||||||
|
|||||||
@@ -24,6 +24,26 @@ def jsonprint(value):
|
|||||||
return json.dumps(value, indent=2, separators=(',', ': '))
|
return json.dumps(value, indent=2, separators=(',', ': '))
|
||||||
|
|
||||||
|
|
||||||
|
def get_db_version(puppetdb):
|
||||||
|
'''
|
||||||
|
Get the version of puppetdb. Version form 3.2 query
|
||||||
|
interface is slightly different on mbeans
|
||||||
|
'''
|
||||||
|
ver = ()
|
||||||
|
try:
|
||||||
|
(major, minor, build) = [int(x) for x in
|
||||||
|
puppetdb.current_version().split('.')]
|
||||||
|
ver = (major, minor, build)
|
||||||
|
log.info("PuppetDB Version %d.%d.%d" % (major, minor, build))
|
||||||
|
except HTTPError as e:
|
||||||
|
log.error(str(e))
|
||||||
|
except ConnectionError as e:
|
||||||
|
log.error(str(e))
|
||||||
|
except EmptyResponseError as e:
|
||||||
|
log.error(str(e))
|
||||||
|
return ver
|
||||||
|
|
||||||
|
|
||||||
def formatvalue(value):
|
def formatvalue(value):
|
||||||
if isinstance(value, str):
|
if isinstance(value, str):
|
||||||
return value
|
return value
|
||||||
|
|||||||
Reference in New Issue
Block a user