Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
43 changes: 42 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,42 @@
# lesson13
# lesson13

> **Table of contents:**

> - [**dist**][0] - directory of puppetexplorer app built by Grunt
> - [**environments**][1] - directory with 2 environments for node1 and node2
> - [**manuals**][2] - dirctory with manuals
> - [**vagrant_scripts**][3] - Vagrant directory of scripts for provisioning VMs
> - [**vagrant_shares**][4] - Vagrant directory of shares for VMs
> - [**Vagrantfile**][5] - Vagrantfile. Provisioning dns, master, node1, node2 VMs
> - [**[agent]-node1-puppet.conf**][6] - configuration file of puppet on node1
> - [**[agent]-node2-puppet.conf**][7] - configuration file of puppet on node2
> - [**master1.kuzniatsou.local.conf**][12] - Apache virt host for puppetexplorer
> - [**puppet.conf**][8] - configuration file of puppet on master
> - [**puppetdb.conf**][9] - configuration file of puppetdb


> **Manuals** directory has 2 options of installation puppetdb and puppexplorer:
> - [Installing_puppetdb_and_puppetexplorer_as_modules.txt][10]
> - [Manual_installing_puppetdb_and_puppetexplorer.txt][11]


### Report of the node2.kuzniatsou.local.
![alt text](screens/node2_events.png "node2")

### Main dashboard of the master1.kuzniatsou.local.
![alt text](screens/master_main.png "master")

[0]: https://github.com/ngkuznetsov/lesson13/tree/mikalai_kuzniatsou/dist
[1]: https://github.com/ngkuznetsov/lesson13/tree/mikalai_kuzniatsou/environments
[2]: https://github.com/ngkuznetsov/lesson13/tree/mikalai_kuzniatsou/manuals
[3]: https://github.com/ngkuznetsov/lesson13/tree/mikalai_kuzniatsou/vagrant_scripts
[4]: https://github.com/ngkuznetsov/lesson13/tree/mikalai_kuzniatsou/vagrant_shares
[5]: https://github.com/ngkuznetsov/lesson13/blob/mikalai_kuzniatsou/Vagrantfile
[6]: https://github.com/ngkuznetsov/lesson13/blob/mikalai_kuzniatsou/%5Bagent%5D-node1-puppet.conf
[7]: https://github.com/ngkuznetsov/lesson13/blob/mikalai_kuzniatsou/%5Bagent%5D-node2-puppet.conf
[8]: https://github.com/ngkuznetsov/lesson13/blob/mikalai_kuzniatsou/puppet.conf
[9]: https://github.com/ngkuznetsov/lesson13/blob/mikalai_kuzniatsou/puppetdb.conf
[10]: https://github.com/ngkuznetsov/lesson13/blob/mikalai_kuzniatsou/manuals/Manual_installing_puppetdb_and_puppetexplorer.txt
[11]: https://github.com/ngkuznetsov/lesson13/blob/mikalai_kuzniatsou/manuals/Manual_installing_puppetdb_and_puppetexplorer.txt
[12]: https://github.com/ngkuznetsov/lesson13/blob/mikalai_kuzniatsou/master1.kuzniatsou.local.conf

56 changes: 56 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
config.vm.define "dns" do |dns|
dns.vm.box = "sbeliakou/centos-7.2-x86_64-minimal"
dns.vm.hostname = "dns.kuzniatsou.local"
dns.vm.synced_folder "vagrant_shares/dns", "/tmp/dns"
dns.vm.network "private_network", ip: "192.168.33.99"
dns.vm.provider "virtualbox" do |vb|
vb.memory = "512"
vb.cpus = "1"
dns.vm.provision "shell", path: "./vagrant_scripts/dns.sh"
end
end

config.vm.define "master1" do |master1|
master1.vm.box = "sbeliakou/centos-7.2-x86_64-minimal"
master1.vm.hostname = "master1.kuzniatsou.local"
master1.vm.synced_folder "vagrant_shares/master", "/tmp/master1"
master1.vm.network "private_network", ip: "192.168.33.190"
master1.vm.provider "virtualbox" do |vb|
vb.memory = "4096"
vb.cpus = "2"
master1.vm.provision "shell", path: "./vagrant_scripts/master.sh"
end
end

config.vm.define "node1" do |node1|
node1.vm.box = "sbeliakou/centos-7.2-x86_64-minimal"
node1.vm.hostname = "node1.kuzniatsou.local"
node1.vm.synced_folder "vagrant_shares/node1", "/tmp/node1"
node1.vm.network "private_network", ip: "192.168.33.91"
node1.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
vb.cpus = "1"
node1.vm.provision "shell", path: "./vagrant_scripts/node1.sh"
end
end

config.vm.define "node2" do |node2|
node2.vm.box = "sbeliakou/centos-7.2-x86_64-minimal"
node2.vm.hostname = "node2.kuzniatsou.local"
node2.vm.synced_folder "vagrant_shares/node2", "/tmp/node2"
node2.vm.network "private_network", ip: "192.168.33.92"
node2.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
vb.cpus = "1"
node2.vm.provision "shell", path: "./vagrant_scripts/node2.sh"
end
end
end
5 changes: 5 additions & 0 deletions [agent]-node1-puppet.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[agent]
use_srv_records = true
srv_domain = kuzniatsou.local
runinterval = 60s
waitforcert = 20s
6 changes: 6 additions & 0 deletions [agent]-node2-puppet.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[agent]
use_srv_records = true
srv_domain = kuzniatsou.local
environment = prod
runinterval = 60s
waitforcert = 20s
135 changes: 135 additions & 0 deletions dist/app.js

Large diffs are not rendered by default.

70 changes: 70 additions & 0 deletions dist/app/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import angular from 'angular';
import 'angular-route';
import 'angular-animate';
import 'angular-google-chart';
import 'angular-moment';
import 'angular-bootstrap';

angular.module('app', [
'ngRoute',
'ngAnimate',
'googlechart',
'angularMoment',
'ui.bootstrap',
]).run(($rootScope, $location, $http, PuppetDB) => {
// Make the $location service available in root scope
$rootScope.location = $location;
$rootScope.isLoading = () => $http.pendingRequests.length !== 0;
$rootScope.clearError = () => { $rootScope.error = null; };
$rootScope.$on('queryChange', $rootScope.clearError);
$rootScope.$on('queryChange', PuppetDB.cancel);
$rootScope.$on('filterChange', PuppetDB.cancel);
$rootScope.changePage = (page) => {
$location.search('page', page);
$rootScope.$broadcast('pageChange', { page });
};
});

angular.module('app').factory('$exceptionHandler', ($injector, $log) =>
(exception, cause) => {
$log.error(exception, cause);
if (!cause) {
const $rootScope = $injector.get('$rootScope');
$rootScope.error = exception.message;
}
}
);

angular.module('app').config(($routeProvider) =>
$routeProvider.when('/dashboard', {
templateUrl: 'controllers/dashboard/dashboard.tpl.html',
controller: 'DashboardCtrl',
controllerAs: 'dashboard',
reloadOnSearch: false,
})
.when('/nodes', {
templateUrl: 'controllers/nodelist/nodelist.tpl.html',
controller: 'NodeListCtrl',
controllerAs: 'nodeList',
reloadOnSearch: false,
})
.when('/node/:node', {
templateUrl: 'controllers/nodedetail/nodedetail.tpl.html',
controller: 'NodeDetailCtrl',
controllerAs: 'nodeDetail',
reloadOnSearch: false,
})
.when('/events', {
templateUrl: 'controllers/events/events.tpl.html',
controller: 'EventsCtrl',
controllerAs: 'events',
reloadOnSearch: false,
})
.when('/facts', {
templateUrl: 'controllers/facts/facts.tpl.html',
controller: 'FactsCtrl',
controllerAs: 'facts',
reloadOnSearch: false,
})
.otherwise({ redirectTo: '/dashboard' })
);
46 changes: 46 additions & 0 deletions dist/app/config.js.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// List of PuppetDB servers, pairs of name, URL and $http config object
// The first one will be used as the default server
PUPPETDB_SERVERS = [
['production', '/api'],
['testing', '/api']
];

// A list of important facts that you want shown in the node detail view
NODE_FACTS = [
'operatingsystem',
'operatingsystemrelease',
'manufacturer',
'productname',
'processorcount',
'memorytotal',
'ipaddress'
];

// The amount of hours since the last check-in after which a node is considered
// unresponsive
UNRESPONSIVE_HOURS = 2;

// Customisable dashboard panels
// type can be either 'primary', 'success', 'info', 'warning' or 'danger'
// Different types will be displayed with different colors
DASHBOARD_PANELS = [
{
name: 'Unresponsive nodes',
type: 'danger',
query: '#node.report_timestamp < @"now - 2 hours"'
},
{
name: 'Nodes in production env',
type: 'success',
query: '#node.catalog_environment = production'
},
{
name: 'Nodes in non-production env',
type: 'warning',
query: '#node.catalog_environment != production'
}
];

// Google Analytics settings
GA_TRACKING_ID = 'UA-XXXXXXXX-YY';
GA_DOMAIN = 'auto';
78 changes: 78 additions & 0 deletions dist/app/controllers/dashboard/dashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/* global angular DASHBOARD_PANELS */
angular.module('app').controller('DashboardCtrl', class {
constructor($scope, PuppetDB, $location) {
this.loadMetrics = this.loadMetrics.bind(this);
this.$scope = $scope;
this.PuppetDB = PuppetDB;
this.$location = $location;
this.$scope.$on('queryChange', this.loadMetrics);
this.major = this.minor = this.patch = null;
this.checkVersion();
}

loadMetrics() {
this.getBean('num-nodes', 'activeNodes');
this.getBean('num-resources', 'resources');
this.getBean('avg-resources-per-node', 'avgResources');
this.getBean('pct-resource-dupes', 'resDuplication', 100);

if (DASHBOARD_PANELS) {
this.$scope.panels = DASHBOARD_PANELS;
} else {
this.$scope.panels = [];
}
for (const panel of this.$scope.panels) {
panel.count = undefined; // reset if we switched server
this.getNodeCount(panel.query, (count) => { panel.count = String(count); });
}

this.$scope.panelWidth = Math.max(2, Math.floor(12 / this.$scope.panels.length));
}

getBean(name, scopeName, multiply = 1) {
this.$scope[scopeName] = undefined;
const bean = this.major > 3 ?
'puppetlabs.puppetdb.population' : 'puppetlabs.puppetdb.query.population';
const metric = this.major > 3 ?
`${bean}:name=${name}` : `${bean}:type=default,name=${name}`;
return this.PuppetDB.getBean(metric)
.success((data) => {
this.$scope[scopeName] = (angular.fromJson(data).Value * multiply)
.toLocaleString()
.replace(/^(.*\..).*/, '$1');
})
.error((data, status) => {
if (status !== 0) {
throw new Error(`Could not fetch metric ${name} from PuppetDB`);
}
});
}

getNodeCount(query, callback) {
this.PuppetDB.query(
'nodes',
['extract', [['function', 'count']], this.PuppetDB.parse(query)],
{},
(data) => callback(data[0].count)
);
}

setQuery(query) {
this.$location.search('query', query);
return this.$location.path('/nodes');
}

checkVersion() {
return this.PuppetDB.getVersion()
.success(data => {
this.major = parseInt(data.version.split('.')[0], 10);
this.minor = parseInt(data.version.split('.')[1], 10);
this.patch = parseInt(data.version.split('.')[2], 10);
if (this.major < 4 || (this.major === 3 && this.minor < 2)) {
throw new Error('This version of Puppet Explorer requires PuppetDB version 3.2.0+' +
`, you are running PuppetDB ${data.version}`);
}
return this.loadMetrics();
});
}
});
Loading