Skip to content

Commit

Permalink
Merge pull request #32 from dalen/puppetdb3
Browse files Browse the repository at this point in the history
Add PuppetDB 3 support
  • Loading branch information
dalen committed Aug 19, 2015
2 parents f139963 + 43e917c commit f7f80c3
Show file tree
Hide file tree
Showing 26 changed files with 67 additions and 232 deletions.
6 changes: 3 additions & 3 deletions app/config.js.example
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ DASHBOARD_PANELS = [
{
name: 'Unresponsive nodes',
type: 'danger',
query: '#node.report-timestamp < @"now - 2 hours"'
query: '#node.report_timestamp < @"now - 2 hours"'
},
{
name: 'Nodes in production env',
type: 'success',
query: '#node.catalog-environment = production'
query: '#node.catalog_environment = production'
},
{
name: 'Nodes in non-production env',
type: 'warning',
query: '#node.catalog-environment != production'
query: '#node.catalog_environment != production'
}
];

Expand Down
10 changes: 5 additions & 5 deletions app/controllers/dashboard/dashboard.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ angular.module('app').controller 'DashboardCtrl', class
@$scope.panelWidth = Math.max(2, Math.floor(12 / @$scope.panels.length))
@checkVersion()

getBean: (name, scopeName, multiply = 1, bean = 'com.puppetlabs.puppetdb.query.population') ->
getBean: (name, scopeName, multiply = 1, bean = 'puppetlabs.puppetdb.query.population') ->
@$scope[scopeName] = undefined
@PuppetDB.query("metrics/mbean/#{bean}:type=default,name=#{name}")
@PuppetDB.getBean("#{bean}:type=default,name=#{name}")
.success (data) =>
@$scope[scopeName] = (angular.fromJson(data).Value * multiply)
.toLocaleString()
Expand All @@ -49,11 +49,11 @@ angular.module('app').controller 'DashboardCtrl', class
@$location.path "/nodes"

checkVersion: () ->
@PuppetDB.query("version")
@PuppetDB.getVersion()
.success (data) ->
major = parseInt(data.version.split('.')[0], 10)
minor = parseInt(data.version.split('.')[1], 10)
patch = parseInt(data.version.split('.')[2], 10)
unless major >= 2 and minor >= 2
throw new Error("This version of Puppet Explorer requires PuppetDB version 2.2.0" +
unless major >= 3
throw new Error("This version of Puppet Explorer requires PuppetDB version 3.0.0+" +
", you are running PuppetDB #{data.version}")
10 changes: 5 additions & 5 deletions app/controllers/dashboard/dashboard.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ <h3>Syntax</h3>
For example <code>@"now - 2 hours"</code>.</p>

<p>A <code>#</code> sign can be used to do a subquery, against the nodes endpoint for example to
query the <code>report-timestamp</code>, <code>catalog-timestamp</code> or <code>facts-timestamp</code>
fields. For example <code>#node.report-timestamp < @"now - 2 hours"</code>.</p>
query the <code>report_timestamp</code>, <code>catalog_timestamp</code> or <code>facts_timestamp</code>
fields. For example <code>#node.report_timestamp < @"now - 2 hours"</code>.</p>

<p>A subquery using the <code>#</code> sign can have a block of expressions instead of a single
expression. For example <code>#node { report-timestamp > @"now - 4 hours" and
report-timestamp < @"now - 2 hours" }</code></p>
expression. For example <code>#node { report_timestamp > @"now - 4 hours" and
report_timestamp < @"now - 2 hours" }</code></p>

<p>A bare string without comparison operator will be treated as a regexp match against the certname.</p>
</div>
Expand Down Expand Up @@ -108,7 +108,7 @@ <h3>Query Examples</h3>
</div>
Nodes that haven't reported in the last 2 hours
<div class="well well-sm">
<tt>#node.report-timestamp<@"now - 2 hours"</tt>
<tt>#node.report_timestamp<@"now - 2 hours"</tt>
</div>
</div>
</div>
14 changes: 7 additions & 7 deletions app/controllers/events/events.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ angular.module("app").controller "EventsCtrl", class
createEventQuery: (exclude = false) ->
query = ["and"]
if @mode.current == 'latest'
query.push ["=", "latest-report?", true]
query.push ["=", "latest_report?", true]
else if @mode.current == 'report'
query.push ["=", "report", @$scope.reportHash]
else
Expand All @@ -60,9 +60,9 @@ angular.module("app").controller "EventsCtrl", class
cc = @$location.search().containing_class
if cc is 'none'
cc = null
query.push([ "=", "containing-class", cc])
query.push([ "=", "containing_class", cc])
if @$location.search().resource_type? and exclude != 'resource_type'
query.push([ "=", "resource-type", @$location.search().resource_type])
query.push([ "=", "resource_type", @$location.search().resource_type])
if @$location.search().status? and exclude != 'status'
query.push([ "=", "status", @$location.search().status.toLowerCase()])

Expand All @@ -80,7 +80,7 @@ angular.module("app").controller "EventsCtrl", class
{
offset: @$scope.perPage * ((@$location.search().page || 1) - 1)
limit: @$scope.perPage
"order-by": angular.toJson([ field: "timestamp", order: "desc" ]),
order_by: angular.toJson([ field: "timestamp", order: "desc" ]),
}
(data, total) =>
@$scope.numItems = total
Expand All @@ -101,7 +101,7 @@ angular.module("app").controller "EventsCtrl", class
@$location.search().query
@createEventQuery('containing_class')
{
'summarize-by': 'containing-class'
summarize_by: 'containing_class'
}
(data, total) =>
chartData = []
Expand All @@ -118,7 +118,7 @@ angular.module("app").controller "EventsCtrl", class
@$location.search().query
@createEventQuery('resource_type')
{
'summarize-by': 'resource'
summarize_by: 'resource'
}
(data, total) =>
chartData = []
Expand All @@ -137,7 +137,7 @@ angular.module("app").controller "EventsCtrl", class
@$location.search().query
@createEventQuery('status')
{
'summarize-by': 'resource'
summarize_by: 'resource'
}
(data, total) =>
chartData = [
Expand Down
18 changes: 9 additions & 9 deletions app/controllers/events/events.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ <h3 class="panel-title">Event status</h3>
</tr></thead>
<tbody ng-repeat="event in events.events">
<tr ng-class="events.color(event.status)" ng-click="events.toggleRow(event)">
<td>{{event["certname"]}}</td>
<td>{{event["resource-type"]}}</td>
<td>{{event["resource-title"]}}</td>
<td>{{event["property"]}}</td>
<td>{{event["old-value"]}}</td>
<td>{{event["new-value"]}}</td>
<td>{{event.certname}}</td>
<td>{{event.resource_type}}</td>
<td>{{event.resource_title}}</td>
<td>{{event.property}}</td>
<td>{{event.old_value}}</td>
<td>{{event.new_value}}</td>
</tr>
<tr>
<td class="reveal-animation" ng-if="event.show" colspan="6">
Expand All @@ -98,13 +98,13 @@ <h3 class="panel-title">Event status</h3>
</tr>
<tr>
<th>Containing-class</th>
<td>{{event["containing-class"]}}</td>
<td>{{event.containing_class}}</td>
</tr>
<tr>
<th>Containment-path</th>
<td>
<ol class="breadcrumb">
<li ng-repeat="container in event['containment-path']">{{container}}</li>
<li ng-repeat="container in event.containment_path">{{container}}</li>
</ol>
</td>
</tr>
Expand All @@ -114,7 +114,7 @@ <h3 class="panel-title">Event status</h3>
</tr>
<tr>
<th>Timestamp</th>
<td title="{{event['timestamp']}}" am-time-ago="event['timestamp']"></td>
<td title="{{event.timestamp}}" am-time-ago="event.timestamp"></td>
</tr>
<tr ng-click="events.selectReport(event.report)">
<th>Report</th>
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/facts/facts.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ angular.module("app").controller "FactsCtrl", class
#
# Returns: `undefined`
getFactNames: ->
@PuppetDB.query("fact-paths", { "order-by": angular.toJson([ field: "path", order: "asc" ]) })
@PuppetDB.query("fact-paths", { order_by: angular.toJson([ field: "path", order: "asc" ]) })
.success (data, status, headers, config) =>
@factPaths = (fact.path for fact in angular.fromJson(data) when fact.path[0][0] isnt '_')
.error (data, status, headers, config) ->
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/nodedetail/nodedetail.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ angular.module("app").controller "NodeDetailCtrl", class
@$location.search().query
["=", "certname", @node]
{
'order-by': angular.toJson([field: "end-time", order: "desc"])
'offset': @$scope.perPage * ((@$location.search().page || 1) - 1)
'limit': @$scope.perPage
order_by: angular.toJson([field: "end_time", order: "desc"])
offset: @$scope.perPage * ((@$location.search().page || 1) - 1)
limit: @$scope.perPage
}
(data, total) =>
@reports = data
Expand All @@ -33,7 +33,7 @@ angular.module("app").controller "NodeDetailCtrl", class
null
["=", "report", report.hash]
{
'summarize-by': 'certname'
'summarize_by': 'certname'
}
(data, total) ->
report.events = data[0]
Expand All @@ -48,7 +48,7 @@ angular.module("app").controller "NodeDetailCtrl", class
"fact-contents"
null
["=", "certname", @node]
{ 'order-by': angular.toJson([field: "name", order: "asc"]) }
{ order_by: angular.toJson([field: "name", order: "asc"]) }
(data, total) =>
@facts = data.filter((fact) ->
fact.name[0] isnt '_'
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/nodedetail/nodedetail.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ <h3>{{nodeDetail.node}}</h3>
</tr></thead>
<tbody>
<tr ng-repeat="report in nodeDetail.reports" ng-click="nodeDetail.selectReport(report.hash)">
<td title="{{report['end-time']}}">
<span am-time-ago="report['end-time']"></span>
<td title="{{report.end_time}}">
<span am-time-ago="report.end_time"></span>
</td>
<td class="text-center">{{report.events.successes || ""}}</td>
<td class="text-center">{{report.events.noops || ""}}</td>
Expand Down
16 changes: 8 additions & 8 deletions app/controllers/nodelist/nodelist.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ angular.module("app").controller "NodeListCtrl", class
{
offset: @$scope.perPage * ((@$location.search().page || 1) - 1)
limit: @$scope.perPage
"order-by": angular.toJson([field: "certname", order: "asc"])
order_by: angular.toJson([field: "certname", order: "asc"])
}
(data, total) =>
@$scope.numItems = total
Expand All @@ -45,10 +45,10 @@ angular.module("app").controller "NodeListCtrl", class
@PuppetDB.parseAndQuery(
"event-counts"
null
["and", ["=", "certname", node.certname], ["=", "latest-report?", true]]
["and", ["=", "certname", node.certname], ["=", "latest_report?", true]]
{
'summarize-by': 'certname'
'order-by': angular.toJson([field: "certname", order: "asc"])
summarize_by: 'certname'
order_by: angular.toJson([field: "certname", order: "asc"])
}
do (node) ->
(data, total) ->
Expand All @@ -73,8 +73,8 @@ angular.module("app").controller "NodeListCtrl", class
null
["=", "certname", node.certname]
{
'order-by': angular.toJson([field: "receive-time", order: "desc"])
'limit': 1
order_by: angular.toJson([field: "receive_time", order: "desc"])
limit: 1
}
do (node) ->
(data, total) ->
Expand Down Expand Up @@ -120,9 +120,9 @@ angular.module("app").controller "NodeListCtrl", class

# Return if a node is unresponsive or not
nodeUnresponsive: (node) ->
return true unless node['report-timestamp']?
return true unless node.report_timestamp?
if UNRESPONSIVE_HOURS?
hours = UNRESPONSIVE_HOURS
else
hours = 2
return moment(node['report-timestamp']).isBefore(moment.utc().subtract(hours,'hours'))
return moment(node.report_timestamp).isBefore(moment.utc().subtract(hours,'hours'))
2 changes: 1 addition & 1 deletion app/controllers/nodelist/nodelist.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<td ng-click="nodeList.selectNode(node)">{{node.certname}}</td>
<td title="{{node['catalog-timestamp']}}">
<span class="glyphicon glyphicon-warning-sign text-warning" ng-if="nodeList.nodeUnresponsive(node)"></span>
<span am-time-ago="node['report-timestamp']"></span>
<span am-time-ago="node.report_timestamp"></span>
</td>
<td class="text-center">{{node.events.successes || ""}}</td>
<td class="text-center">{{node.events.noops || ""}}</td>
Expand Down
22 changes: 20 additions & 2 deletions app/services/puppetdb/puppetdb.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ angular.module('app').factory 'PuppetDB', ($http,
config = @serverConfig()
config.params = params
config.timeout = @canceller.promise
$http.get("#{@serverUrl()}/#{@apiVersion}/#{endpoint}", config)
$http.get("#{@serverUrl()}/pdb/query/#{@apiVersion}/#{endpoint}", config)

# Public: Combined function to both parse and query PuppetDB.
#
Expand Down Expand Up @@ -92,7 +92,7 @@ angular.module('app').factory 'PuppetDB', ($http,

params.query = angular.toJson(query)
if endpoint in ['nodes', 'reports', 'events', 'facts']
params['include-total'] = true
params['include_total'] = true

# Start querying
@query(endpoint, params)
Expand All @@ -104,3 +104,21 @@ angular.module('app').factory 'PuppetDB', ($http,
cancel: =>
@canceller.resolve("user cancelled")
@canceller = $q.defer()

# Public: Get a bean value, returns a promise just like $http
#
# name - The {String} bean name
#
# Returns: A promise from $http
getBean: (name) ->
config = @serverConfig()
config.timeout = @canceller.promise
$http.get("#{@serverUrl()}/metrics/v1/mbeans/#{name}", config)

# Public: Get PuppetDB version, returns a promise just like $http
#
# Returns: A promise from $http
getVersion: ->
config = @serverConfig()
config.timeout = @canceller.promise
$http.get("#{@serverUrl()}/pdb/meta/v1/version", config)
20 changes: 0 additions & 20 deletions mocks/server/0751304c6c14ebb40572e825e9168092c9c23c67.json

This file was deleted.

17 changes: 0 additions & 17 deletions mocks/server/1fe279d88aa0bfcc4084bd2b58f73186434eb3ea.json

This file was deleted.

8 changes: 0 additions & 8 deletions mocks/server/2558791bea8ac8a2ff649334b9d73284cd276f3d.json

This file was deleted.

6 changes: 0 additions & 6 deletions mocks/server/25bef5bb6d0ce166208674931a5396d43bedabd4.json

This file was deleted.

8 changes: 0 additions & 8 deletions mocks/server/4086f6763db26507f34278e4eb01da8bd1926c43.json

This file was deleted.

8 changes: 0 additions & 8 deletions mocks/server/4b199767ded0ea8f7613bc1c9c8a3a28f20182c6.json

This file was deleted.

Loading

0 comments on commit f7f80c3

Please sign in to comment.