From c7c793b699247c1ad07e351768da231f2615200f Mon Sep 17 00:00:00 2001 From: Vincent Fournier Date: Sat, 18 Jul 2015 12:51:18 -0400 Subject: [PATCH] Improve application configuration Change-Id: Ic689dee2b15ace091a4e61995d3c64641660b899 --- Gruntfile.js | 4 + app/app.js | 12 +- app/assets/sass/app.scss | 2 +- .../authentication/authentication.js | 1 + app/components/config/componentsConfig.json | 252 +++++ app/components/config/config.js | 48 +- app/components/config/config.json | 906 +++++++++++------- app/components/datasource/datasource.js | 193 ++++ .../actionbar/actionbar.html | 1 + .../directive/actionbar/actionbar.js | 22 + .../component_acknowledge/acknowledge.html | 0 .../component_acknowledge/acknowledge.js | 28 +- .../component_downtime/downtime.html | 0 .../actionbar/component_downtime/downtime.js | 39 + .../actionbar/component_filter/filter.html | 16 +- .../actionbar/component_filter/filter.js | 49 + .../actionbar/component_more/more.html | 0 .../actionbar/component_more/more.js | 13 + .../actionbar/component_recheck/recheck.html | 0 .../actionbar/component_recheck/recheck.js | 30 + .../search_filter.html | 0 .../component_search_filter/search_filter.js | 19 + app/components/directive/directive.js | 11 + app/components/directive/host/host.html | 6 + app/components/directive/host/host.js | 37 + .../directive/host/host_cpu/host_cpu.html | 15 + .../directive/host/host_cpu/host_cpu.js | 12 + .../directive/host/host_info/host_info.html | 35 + .../directive/host/host_info/host_info.js | 12 + .../directive/host/host_live/host_live.html | 15 + .../directive/host/host_live/host_live.js | 12 + .../directive/host/host_load/host_load.html | 16 + .../directive/host/host_load/host_load.js | 12 + .../directive/host/host_main/host_main.html | 9 + .../directive/host/host_main/host_main.js | 12 + .../host_services_list.html | 19 + .../host_services_list/host_services_list.js | 12 + app/components/directive/service/service.html | 5 + app/components/directive/service/service.js | 32 + .../service_graphs/service_graphs.html | 2 +- .../service/service_graphs/service_graphs.js | 9 + .../service/service_info/service_info.html | 8 +- .../service/service_info/service_info.js | 9 + .../service/service_live/service_live.html | 15 + .../service/service_live/service_live.js | 9 + .../service/service_main/service_main.html | 7 + .../service/service_main/service_main.js | 12 + .../service_metrics/service_metrics.html | 3 + .../service_metrics/service_metrics.js | 13 +- .../cell_status_duration.html | 3 + .../cell_status_duration.js | 0 .../cell_status_event/cell_status_event.html | 0 .../cell_status_event/cell_status_event.js | 14 +- .../cell_status_event_event_type.html | 3 + .../cell_status_event_event_type.js | 0 .../cell_status_event_host_name.html | 3 + .../cell_status_event_host_name.js | 0 .../cell_status_event_output.html | 2 +- .../cell_status_event_output.js | 0 .../cell_status_event_service.html | 3 + .../cell_status_event_service.js | 0 .../cell_status_event_time.html | 3 + .../cell_status_event_time.js | 0 .../cell_status_host/cell_status_host.html | 2 +- .../cell_status_host/cell_status_host.js | 2 +- .../cell_status_host_address.html | 2 +- .../cell_status_host_address.js | 0 .../cell_status_host_status.html | 0 .../cell_status_host_status.js | 0 .../cell_status_last_check.html | 3 + .../cell_status_last_check.js | 0 .../cell_status_service_check.html | 8 + .../cell_status_service_check.js | 4 +- .../table/state_icon/state_icon.html | 0 .../directive/table/state_icon/state_icon.js | 48 + app/components/directive/table/table.html | 40 + app/components/{ => directive}/table/table.js | 230 ++--- .../{ => directive}/table/table_test.js | 0 app/components/directive/tabpanel/panel.html | 6 + .../directive/tabpanel/tabpanel.html | 17 + app/components/directive/tabpanel/tabpanel.js | 50 + .../{ => directive}/tactical/_tactical.scss | 0 .../current_health/current_health.html | 0 .../tactical/current_health/current_health.js | 2 +- .../current_health/current_health_test.js | 0 .../status_overview/status_overview.html | 0 .../status_overview/status_overview.js | 2 +- .../status_overview/status_overview_test.js | 0 .../directive/tactical/tactical.html | 19 + app/components/directive/tactical/tactical.js | 51 + .../{ => directive}/tactical/tactical_test.js | 0 .../top_alert_producers.html | 0 .../top_alert_producers.js | 2 +- .../top_alert_producers_test.js | 0 app/components/directive/title/title.html | 14 + app/components/directive/title/title.js | 22 + app/components/host/host.html | 17 - app/components/host/host.js | 68 -- app/components/host/host_cpu/host_cpu.html | 15 - app/components/host/host_cpu/host_cpu.js | 12 - app/components/host/host_info/host_info.html | 35 - app/components/host/host_info/host_info.js | 17 - app/components/host/host_live/host_live.html | 15 - app/components/host/host_live/host_live.js | 17 - app/components/host/host_load/host_load.html | 16 - app/components/host/host_load/host_load.js | 12 - app/components/host/host_main/host_main.html | 7 - app/components/host/host_main/host_main.js | 17 - .../host_services_list.html | 19 - .../host_services_list/host_services_list.js | 12 - app/components/service/service.html | 13 - app/components/service/service.js | 50 - .../service/service_graphs/service_graphs.js | 28 - .../service/service_info/service_info.js | 17 - .../service/service_live/service_live.html | 15 - .../service/service_live/service_live.js | 19 - .../service/service_main/service_main.html | 7 - .../service/service_main/service_main.js | 19 - .../service_metrics/service_metrics.html | 3 - app/components/surveil/query.js | 18 + app/components/surveil/status.js | 526 ++++------ app/components/table/actionbar/actionbar.js | 25 - .../table/actionbar/actions/actions.js | 111 --- .../actionbar/component_downtime/downtime.js | 43 - .../actionbar/component_filter/filter.js | 39 - .../table/actionbar/component_more/more.js | 13 - .../actionbar/component_recheck/recheck.js | 36 - .../component_search_filter/search_filter.js | 19 - .../cell_status_duration.html | 3 - .../cell_status_event_event_type.html | 3 - .../cell_status_event_host_name.html | 3 - .../cell_status_event_service.html | 3 - .../cell_status_event_time.html | 3 - .../cell_status_last_check.html | 3 - .../cell_status_service_check.html | 8 - app/components/table/state_icon/state_icon.js | 44 - app/components/table/table.html | 35 - app/components/tactical/tactical.html | 15 - app/components/tactical/tactical.js | 84 -- app/components/topbar/topbar.html | 2 +- app/components/topbar/topbar.js | 43 +- app/index.html | 90 +- app/templates/config/config.js | 2 +- app/templates/dashboard/dashboard.html | 151 --- app/templates/dashboard/dashboard.js | 68 -- app/templates/host/host.html | 2 +- app/templates/host/host.js | 16 +- app/templates/page/page.html | 3 + app/templates/page/page.js | 36 + app/templates/service/service.html | 2 +- app/templates/service/service.js | 16 +- app/templates/tables/tables.html | 5 - app/templates/tables/tables.js | 58 -- 153 files changed, 2300 insertions(+), 2227 deletions(-) create mode 100644 app/components/config/componentsConfig.json create mode 100644 app/components/datasource/datasource.js rename app/components/{table => directive}/actionbar/actionbar.html (52%) create mode 100644 app/components/directive/actionbar/actionbar.js rename app/components/{table => directive}/actionbar/component_acknowledge/acknowledge.html (100%) rename app/components/{table => directive}/actionbar/component_acknowledge/acknowledge.js (50%) rename app/components/{table => directive}/actionbar/component_downtime/downtime.html (100%) create mode 100644 app/components/directive/actionbar/component_downtime/downtime.js rename app/components/{table => directive}/actionbar/component_filter/filter.html (51%) create mode 100644 app/components/directive/actionbar/component_filter/filter.js rename app/components/{table => directive}/actionbar/component_more/more.html (100%) create mode 100644 app/components/directive/actionbar/component_more/more.js rename app/components/{table => directive}/actionbar/component_recheck/recheck.html (100%) create mode 100644 app/components/directive/actionbar/component_recheck/recheck.js rename app/components/{table => directive}/actionbar/component_search_filter/search_filter.html (100%) create mode 100644 app/components/directive/actionbar/component_search_filter/search_filter.js create mode 100644 app/components/directive/directive.js create mode 100644 app/components/directive/host/host.html create mode 100644 app/components/directive/host/host.js create mode 100644 app/components/directive/host/host_cpu/host_cpu.html create mode 100644 app/components/directive/host/host_cpu/host_cpu.js create mode 100644 app/components/directive/host/host_info/host_info.html create mode 100644 app/components/directive/host/host_info/host_info.js create mode 100644 app/components/directive/host/host_live/host_live.html create mode 100644 app/components/directive/host/host_live/host_live.js create mode 100644 app/components/directive/host/host_load/host_load.html create mode 100644 app/components/directive/host/host_load/host_load.js create mode 100644 app/components/directive/host/host_main/host_main.html create mode 100644 app/components/directive/host/host_main/host_main.js create mode 100644 app/components/directive/host/host_services_list/host_services_list.html create mode 100644 app/components/directive/host/host_services_list/host_services_list.js create mode 100644 app/components/directive/service/service.html create mode 100644 app/components/directive/service/service.js rename app/components/{ => directive}/service/service_graphs/service_graphs.html (57%) create mode 100644 app/components/directive/service/service_graphs/service_graphs.js rename app/components/{ => directive}/service/service_info/service_info.html (50%) create mode 100644 app/components/directive/service/service_info/service_info.js create mode 100644 app/components/directive/service/service_live/service_live.html create mode 100644 app/components/directive/service/service_live/service_live.js create mode 100644 app/components/directive/service/service_main/service_main.html create mode 100644 app/components/directive/service/service_main/service_main.js create mode 100644 app/components/directive/service/service_metrics/service_metrics.html rename app/components/{ => directive}/service/service_metrics/service_metrics.js (55%) create mode 100644 app/components/directive/table/cell_status_duration/cell_status_duration.html rename app/components/{ => directive}/table/cell_status_duration/cell_status_duration.js (100%) rename app/components/{ => directive}/table/cell_status_event/cell_status_event.html (100%) rename app/components/{ => directive}/table/cell_status_event/cell_status_event.js (75%) create mode 100644 app/components/directive/table/cell_status_event_event_type/cell_status_event_event_type.html rename app/components/{ => directive}/table/cell_status_event_event_type/cell_status_event_event_type.js (100%) create mode 100644 app/components/directive/table/cell_status_event_host_name/cell_status_event_host_name.html rename app/components/{ => directive}/table/cell_status_event_host_name/cell_status_event_host_name.js (100%) rename app/components/{ => directive}/table/cell_status_event_output/cell_status_event_output.html (60%) rename app/components/{ => directive}/table/cell_status_event_output/cell_status_event_output.js (100%) create mode 100644 app/components/directive/table/cell_status_event_service/cell_status_event_service.html rename app/components/{ => directive}/table/cell_status_event_service/cell_status_event_service.js (100%) create mode 100644 app/components/directive/table/cell_status_event_time/cell_status_event_time.html rename app/components/{ => directive}/table/cell_status_event_time/cell_status_event_time.js (100%) rename app/components/{ => directive}/table/cell_status_host/cell_status_host.html (77%) rename app/components/{ => directive}/table/cell_status_host/cell_status_host.js (88%) rename app/components/{ => directive}/table/cell_status_host_address/cell_status_host_address.html (57%) rename app/components/{ => directive}/table/cell_status_host_address/cell_status_host_address.js (100%) rename app/components/{ => directive}/table/cell_status_host_status/cell_status_host_status.html (100%) rename app/components/{ => directive}/table/cell_status_host_status/cell_status_host_status.js (100%) create mode 100644 app/components/directive/table/cell_status_last_check/cell_status_last_check.html rename app/components/{ => directive}/table/cell_status_last_check/cell_status_last_check.js (100%) create mode 100644 app/components/directive/table/cell_status_service_check/cell_status_service_check.html rename app/components/{ => directive}/table/cell_status_service_check/cell_status_service_check.js (81%) rename app/components/{ => directive}/table/state_icon/state_icon.html (100%) create mode 100644 app/components/directive/table/state_icon/state_icon.js create mode 100644 app/components/directive/table/table.html rename app/components/{ => directive}/table/table.js (51%) rename app/components/{ => directive}/table/table_test.js (100%) create mode 100644 app/components/directive/tabpanel/panel.html create mode 100644 app/components/directive/tabpanel/tabpanel.html create mode 100644 app/components/directive/tabpanel/tabpanel.js rename app/components/{ => directive}/tactical/_tactical.scss (100%) rename app/components/{ => directive}/tactical/current_health/current_health.html (100%) rename app/components/{ => directive}/tactical/current_health/current_health.js (80%) rename app/components/{ => directive}/tactical/current_health/current_health_test.js (100%) rename app/components/{ => directive}/tactical/status_overview/status_overview.html (100%) rename app/components/{ => directive}/tactical/status_overview/status_overview.js (75%) rename app/components/{ => directive}/tactical/status_overview/status_overview_test.js (100%) create mode 100644 app/components/directive/tactical/tactical.html create mode 100644 app/components/directive/tactical/tactical.js rename app/components/{ => directive}/tactical/tactical_test.js (100%) rename app/components/{ => directive}/tactical/top_alert_producers/top_alert_producers.html (100%) rename app/components/{ => directive}/tactical/top_alert_producers/top_alert_producers.js (85%) rename app/components/{ => directive}/tactical/top_alert_producers/top_alert_producers_test.js (100%) create mode 100644 app/components/directive/title/title.html create mode 100644 app/components/directive/title/title.js delete mode 100644 app/components/host/host.html delete mode 100644 app/components/host/host.js delete mode 100644 app/components/host/host_cpu/host_cpu.html delete mode 100644 app/components/host/host_cpu/host_cpu.js delete mode 100644 app/components/host/host_info/host_info.html delete mode 100644 app/components/host/host_info/host_info.js delete mode 100644 app/components/host/host_live/host_live.html delete mode 100644 app/components/host/host_live/host_live.js delete mode 100644 app/components/host/host_load/host_load.html delete mode 100644 app/components/host/host_load/host_load.js delete mode 100644 app/components/host/host_main/host_main.html delete mode 100644 app/components/host/host_main/host_main.js delete mode 100644 app/components/host/host_services_list/host_services_list.html delete mode 100644 app/components/host/host_services_list/host_services_list.js delete mode 100644 app/components/service/service.html delete mode 100644 app/components/service/service.js delete mode 100644 app/components/service/service_graphs/service_graphs.js delete mode 100644 app/components/service/service_info/service_info.js delete mode 100644 app/components/service/service_live/service_live.html delete mode 100644 app/components/service/service_live/service_live.js delete mode 100644 app/components/service/service_main/service_main.html delete mode 100644 app/components/service/service_main/service_main.js delete mode 100644 app/components/service/service_metrics/service_metrics.html create mode 100644 app/components/surveil/query.js delete mode 100644 app/components/table/actionbar/actionbar.js delete mode 100644 app/components/table/actionbar/actions/actions.js delete mode 100644 app/components/table/actionbar/component_downtime/downtime.js delete mode 100644 app/components/table/actionbar/component_filter/filter.js delete mode 100644 app/components/table/actionbar/component_more/more.js delete mode 100644 app/components/table/actionbar/component_recheck/recheck.js delete mode 100644 app/components/table/actionbar/component_search_filter/search_filter.js delete mode 100644 app/components/table/cell_status_duration/cell_status_duration.html delete mode 100644 app/components/table/cell_status_event_event_type/cell_status_event_event_type.html delete mode 100644 app/components/table/cell_status_event_host_name/cell_status_event_host_name.html delete mode 100644 app/components/table/cell_status_event_service/cell_status_event_service.html delete mode 100644 app/components/table/cell_status_event_time/cell_status_event_time.html delete mode 100644 app/components/table/cell_status_last_check/cell_status_last_check.html delete mode 100644 app/components/table/cell_status_service_check/cell_status_service_check.html delete mode 100644 app/components/table/state_icon/state_icon.js delete mode 100644 app/components/table/table.html delete mode 100644 app/components/tactical/tactical.html delete mode 100644 app/components/tactical/tactical.js delete mode 100644 app/templates/dashboard/dashboard.html delete mode 100644 app/templates/dashboard/dashboard.js create mode 100644 app/templates/page/page.html create mode 100644 app/templates/page/page.js delete mode 100644 app/templates/tables/tables.html delete mode 100644 app/templates/tables/tables.js diff --git a/Gruntfile.js b/Gruntfile.js index 599aa21..ca02469 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -53,6 +53,10 @@ module.exports = function (grunt) { src: '<%= project.app %>/components/config/config.json', dest: '<%= project.dist %>/components/config/config.json' }, + { + src: '<%= project.app %>/components/config/componentsConfig.json', + dest: '<%= project.dist %>/components/config/componentsConfig.json' + }, { src: '<%= project.app %>/components/config/developmentConfig.json', dest: '<%= project.dist %>/components/config/developmentConfig.json' diff --git a/app/app.js b/app/app.js index d26708b..1bb6648 100644 --- a/app/app.js +++ b/app/app.js @@ -10,16 +10,18 @@ angular.module('bansho', [ 'bansho.topbar', 'bansho.sidebar', 'bansho.surveil', + 'bansho.datasource', + 'bansho.directive', 'bansho.host', 'bansho.service', 'bansho.drupal', 'bansho.drupal.tile', 'bansho.drupal.info', 'bansho.view', - 'bansho.view.dashboard', - 'bansho.view.singleTable', + 'bansho.view.page', 'bansho.view.host', 'bansho.view.service', + 'bansho.view.config', 'bansho.view.drupalDashboard', 'bansho.view.drupal', 'bansho.grafana' @@ -30,11 +32,13 @@ angular.module('bansho', [ }]) // Reinitialise objects on url change - .run(['$rootScope', 'promisesManager', 'reinitDrupalTiles', 'reinitDrupalInfo', - function ($rootScope, promisesManager, reinitDrupalTiles, reinitDrupalInfo) { + .run(['$rootScope', 'promisesManager', 'sharedData', 'reinitDrupalTiles', 'reinitDrupalInfo', 'componentsConfig', + function ($rootScope, promisesManager, sharedData, reinitDrupalTiles, reinitDrupalInfo, componentsConfig) { + componentsConfig.load(); $rootScope.$on('$locationChangeStart', function () { reinitDrupalTiles(); reinitDrupalInfo(); promisesManager.clearAllPromises(); + sharedData.clear(); }); }]); diff --git a/app/assets/sass/app.scss b/app/assets/sass/app.scss index 076b4f1..ece9bab 100644 --- a/app/assets/sass/app.scss +++ b/app/assets/sass/app.scss @@ -54,7 +54,7 @@ @import 'modules-interface/main'; @import '../../components/topbar/topbar'; @import '../../components/sidebar/sidebar'; -@import '../../components/tactical/tactical'; +@import '../../components/directive/tactical/tactical'; //----------------------------------*\ // TEMPORARY MODULES diff --git a/app/components/authentication/authentication.js b/app/components/authentication/authentication.js index d6f3997..d3316e8 100644 --- a/app/components/authentication/authentication.js +++ b/app/components/authentication/authentication.js @@ -11,6 +11,7 @@ angular.module('bansho.authentication', []) .controller('LoginController', ['$scope', '$rootScope', '$location', 'authService', 'configManager', 'themeManager', function ($scope, $rootScope, $location, authService, configManager, themeManager) { themeManager.setTheme(themeManager.THEMES.DEFAULT); + $rootScope.isAuthenticated = false; var login = function (credentials) { authService.login(credentials); diff --git a/app/components/config/componentsConfig.json b/app/components/config/componentsConfig.json new file mode 100644 index 0000000..d44907b --- /dev/null +++ b/app/components/config/componentsConfig.json @@ -0,0 +1,252 @@ +{ + "filters": { + "allHostOpenProblems": { + "name": "Open hosts problems", + "filter": { + "hosts": { + "is": { + "state": [ + "DOWN", + "UNREACHABLE" + ], + "acknowledged": [ + false + ] + } + } + } + }, + "allHostsProblems": { + "name": "Hosts problems", + "filter": { + "hosts": { + "isnot": { + "state": [ + "UP" + ] + } + } + } + }, + "hostOk": { + "name": "All Ok", + "filter": { + "hosts": { + "is": { + "state": [ + "UP" + ] + } + } + } + }, + "hostNotOk": { + "name": "All not Ok", + "filter": { + "hosts": { + "isnot": { + "state": [ + "UP" + ] + } + } + } + }, + "serviceOk": { + "name": "All Ok", + "filter": { + "services": { + "is": { + "state": [ + "OK" + ] + } + } + } + }, + "serviceNotOk": { + "name": "All not Ok", + "filter": { + "services": { + "isnot": { + "state": [ + "OK" + ] + } + } + } + }, + "allAlert": { + "name": "All ALERT", + "filter": { + "events": { + "is": { + "event_type": [ + "ALERT" + ] + } + } + } + }, + "allNotification": { + "name": "All NOTIFICATION", + "filter": { + "events": { + "is": { + "event_type": [ + "NOTIFICATION" + ] + } + } + } + }, + "allOk": { + "name": "All OK", + "filter": { + "hosts": { + "is": { + "state": [ + "UP" + ] + } + }, + "services": { + "is": { + "state": [ + "OK" + ] + } + } + } + }, + "allNotOk": { + "name": "All not OK", + "filter": { + "hosts": { + "isnot": { + "state": [ + "UP" + ] + } + }, + "services": { + "isnot": { + "state": [ + "OK" + ] + } + } + } + }, + "allServices": { + "name": "All", + "filter": { + "hosts": {}, + "services": {} + } + }, + "allServicesProblems": { + "name": "Open services problems", + "filter": { + "services": { + "isnot": { + "state": [ + "OK" + ] + } + } + } + }, + "allServiceOpenProblems": { + "name": "Open services problems", + "filter": { + "services": { + "isnot": { + "state": [ + "OK" + ] + }, + "is": { + "acknowledged": [ + false + ] + } + } + } + }, + "allServiceOpenProblemsOnly": { + "name": "Open services problems", + "filter": { + "services": { + "isnot": { + "state": [ + "OK" + ] + }, + "is": { + "acknowledged": [ + false + ] + } + }, + "hosts": { + "is": { + "state": [ + "UP" + ] + } + } + } + }, + "all": { + "name": "All", + "filter": { + "services": {}, + "hosts": {}, + "events": {} + } + } + }, + "inputSource": { + "hostOpenProblems": { + "provider": "status", + "endpoint": "hosts", + "filter": "allHostOpenProblems" + }, + "serviceOpenProblems": { + "provider": "status", + "endpoint": "services", + "filter": "allServiceOpenProblems" + }, + "serviceOpenProblemsOnly": { + "provider": "status", + "endpoint": "services", + "filter": "allServiceOpenProblemsOnly" + }, + "hostsProblems": { + "provider": "status", + "endpoint": "hosts", + "filter": "allHostsProblems" + }, + "servicesProblems": { + "provider": "status", + "endpoint": "services", + "filter": "allServicesProblems" + }, + "events": { + "provider": "status", + "endpoint": "events", + "filter": "all" + }, + "hosts": { + "provider": "status", + "endpoint": "hosts", + "filter": "all" + }, + "services": { + "provider": "status", + "endpoint": "services", + "filter": "all" + } + } +} diff --git a/app/components/config/config.js b/app/components/config/config.js index 13ebf56..8ac4472 100644 --- a/app/components/config/config.js +++ b/app/components/config/config.js @@ -44,7 +44,50 @@ angular.module('bansho.config', []) }; }]) - .service('configManager', ['$http', '$q', function ($http, $q) { + .service('componentsConfig', ['$http', function($http) { + var componentsConfig; + + this.getFilter = function (name) { + return componentsConfig.filters[name]; + }; + + this.mergeFilters = function (filters) { + var filter = {}; + + angular.forEach(filters, function (f) { + angular.forEach(f, function (endpointFilter, endpoint) { + if (!filter[endpoint]) { + filter[endpoint] = {}; + } + + angular.forEach(endpointFilter, function (constraint, constraintType) { + if (!filter[endpoint][constraintType]) { + filter[endpoint][constraintType] = {}; + } + + angular.forEach(constraint, function (value, key) { + filter[endpoint][constraintType][key] = value; + }); + }); + }); + }); + + return filter; + }; + + this.getInputSource = function (name) { + return componentsConfig.inputSource[name]; + }; + + this.load = function () { + $http.get('components/config/componentsConfig.json') + .success(function(config) { + componentsConfig = config; + }); + }; + }]) + + .service('configManager', ['$http', '$q', 'componentsConfig', function ($http, $q, componentsConfig) { var config = {}, developmentConfig = {}; @@ -112,10 +155,11 @@ angular.module('bansho.config', []) this.fetchConfig = function (useStoredConfig) { var responsePromise = $q.defer(); + componentsConfig.load(); + $http.get('surveil/v2/bansho/config') .success(function (conf) { if (!useStoredConfig || jQuery.isEmptyObject(conf)) { - $http.get('components/config/config.json') .success(function (conf) { config.data = conf; diff --git a/app/components/config/config.json b/app/components/config/config.json index e37055a..53e2508 100644 --- a/app/components/config/config.json +++ b/app/components/config/config.json @@ -3,383 +3,631 @@ "theme": "dark" }, "dashboardConfig": { - "title": "Unhandled service problems", - "refreshInterval": 30, - "template": "dashboard", + "template": "page", + "attributes": { + "refreshInterval": 30 + }, "components": [ - { - "type": "actionbar", - "config": { - "components": [ - "filter", - "acknowledge", - "downtime", - "recheck", - "more", - "search-filter" - ], - "tableId": [ - 0, - 1, - 2, - 3 - ] - } - } - ], - "extra_components": [ { "type": "tactical", - "config": { + "attributes": { "title": "Tactical Overview", - "components": { - "statusOverview": true, - "currentHealth": true, - "topAlertProducers": false - } + "statusOverview": true, + "currentHealth": true, + "topAlertProducers": false } }, { - "type": "table", - "config": { - "title": "Open Hosts problems", - "cells": { - "text": [ - "Host", - "Address", - "Duration", - "Last check", - "Host status" - ], - "name": [ - "status_host", - "status_host_address", - "status_duration", - "status_last_check", - "status_host_status" - ] - }, - "headerFollow": false, - "inputSource": { - "service": "surveilStatus", - "config": { - "apiName": "hosts", - "filters": { - "is": { - "acknowledged": [ - false - ], - "state": [ - "DOWN", - "UNREACHABLE" - ] - } - } + "type": "tabpanel", + "attributes": { + "navigation": [ + { + "title": "Open Problems", + "panelId": "openProblems", + "provider": "nbServicesHostsOpenProblems" + }, + { + "title": "All Problems", + "panelId": "allProblems", + "provider": "nbServicesHostsOpenProblemsDoubleCount" } - }, - "isWrappable": false, - "checkColumn": true, - "noRepeatCell": "" - } - }, - { - "type": "table", - "config": { - "title": "Open Service problems", - "cells": { - "text": [ - "Host", - "Service check", - "Duration", - "Last check" - ], - "name": [ - "status_host", - "status_service_check", - "status_duration", - "status_last_check" - ] - }, - "headerFollow": false, - "inputSource": { - "service": "surveilStatus", - "config": { - "apiName": "services", - "filters": { - "isnot": { - "state": [ - "OK" - ], - "host_state": [ - "DOWN", - "UNREACHABLE" + ] + }, + "components": [ + { + "type": "panel", + "attributes": { + "panelId": "openProblems" + }, + "components": [ + { + "type": "actionbar", + "attributes": { + "tableId": [ + 0, + 1 ] }, - "is": { - "acknowledged": [ - false - ] + "components": [ + { + "type": "actionbar-filter", + "attributes": { + "filters": [ + { + "location": "componentsConfig", + "content": "all" + }, + { + "location": "componentsConfig", + "content": "allOk" + }, + { + "location": "componentsConfig", + "content": "allNotOk" + } + ] + } + }, + { + "type": "actionbar-acknowledge", + "attributes": {} + }, + { + "type": "actionbar-downtime", + "attributes": {} + }, + { + "type": "actionbar-recheck", + "attributes": {} + }, + { + "type": "actionbar-more", + "attributes": {} + }, + { + "type": "actionbar-search-filter", + "attributes": {} + } + ] + }, + { + "type": "title", + "attributes": { + "title": "Open hosts problems", + "item": "host", + "provider": "nbHostsOpenProblems" + } + }, + { + "type": "table", + "attributes": { + "tableId": 0, + "cells": { + "text": [ + "Host", + "Address", + "Duration", + "Last check", + "Host status" + ], + "name": [ + "status_host", + "status_host_address", + "status_duration", + "status_last_check", + "status_host_status" + ] + }, + "headerFollow": false, + "inputSource": "hostOpenProblems", + "isWrappable": false, + "checkColumn": true, + "noRepeatCell": "" + } + }, + { + "type": "title", + "attributes": { + "title": "Open Service Problems", + "item": "service", + "provider": "nbServicesOpenProblemsOnly" + } + }, + { + "type": "table", + "attributes": { + "tableId": 1, + "cells": { + "text": [ + "Host", + "Service check", + "Duration", + "Last check" + ], + "name": [ + "status_host", + "status_service_check", + "status_duration", + "status_last_check" + ] + }, + "headerFollow": false, + "inputSource": "serviceOpenProblemsOnly", + "isWrappable": true, + "checkColumn": true, + "noRepeatCell": "host" } } - } - }, - "isWrappable": true, - "checkColumn": true, - "noRepeatCell": "host" - } - }, - { - "type": "table", - "config": { - "title": "Hosts problems", - "cells": { - "text": [ - "Host", - "Address", - "Duration", - "Last check", - "Host status" - ], - "name": [ - "status_host", - "status_host_address", - "status_duration", - "status_last_check", - "status_host_status" ] }, - "headerFollow": false, - "inputSource": { - "service": "surveilStatus", - "config": { - "apiName": "hosts", - "filters": { - "isnot": { - "state": [ - "UP" + { + "type": "panel", + "attributes": { + "panelId": "allProblems", + "provider": "nbServicesHostsOpenProblems" + }, + "components": [ + { + "type": "actionbar", + "attributes": { + "tableId": [ + 2, + 3 ] + }, + "components": [ + { + "type": "actionbar-filter", + "attributes": { + "filters": [ + { + "location": "componentsConfig", + "content": "all" + }, + { + "location": "componentsConfig", + "content": "allOk" + }, + { + "location": "componentsConfig", + "content": "allNotOk" + } + ] + } + }, + { + "type": "actionbar-acknowledge", + "attributes": {} + }, + { + "type": "actionbar-downtime", + "attributes": {} + }, + { + "type": "actionbar-recheck", + "attributes": {} + }, + { + "type": "actionbar-more", + "attributes": {} + }, + { + "type": "actionbar-search-filter", + "attributes": {} + } + ] + }, + { + "type": "title", + "attributes": { + "title": "Hosts problems", + "item": "host", + "provider": "nbHostsOpenProblems" + } + }, + { + "type": "table", + "attributes": { + "tableId": 2, + "cells": { + "text": [ + "Host", + "Address", + "Duration", + "Lastcheck", + "Hoststatus" + ], + "name": [ + "status_host", + "status_host_address", + "status_duration", + "status_last_check", + "status_host_status" + ] + }, + "headerFollow": false, + "inputSource": "hostsProblems", + "isWrappable": false, + "checkColumn": true, + "noRepeatCell": "" + } + }, + { + "type": "title", + "attributes": { + "title": "Services problems", + "item": "service", + "provider": "nbServicesOpenProblems" + } + }, + { + "type": "table", + "attributes": { + "tableId": 3, + "cells": { + "text": [ + "Host", + "Service check", + "Duration", + "Last check" + ], + "name": [ + "status_host", + "status_service_check", + "status_duration", + "status_last_check" + ] + }, + "headerFollow": false, + "inputSource": "servicesProblems", + "isWrappable": true, + "checkColumn": true, + "noRepeatCell": "host" } } - } - }, - "isWrappable": false, - "checkColumn": true, - "noRepeatCell": "" - } - }, - { - "type": "table", - "config": { - "title": "Services problems", - "cells": { - "text": [ - "Host", - "Service check", - "Duration", - "Last check" - ], - "name": [ - "status_host", - "status_service_check", - "status_duration", - "status_last_check" ] - }, - "headerFollow": false, - "inputSource": { - "service": "surveilStatus", - "config": { - "apiName": "services", - "filters": { - "isnot": { - "state": [ - "OK" - ] - } - } - } - }, - "isWrappable": true, - "checkColumn": true, - "noRepeatCell": "host" - } + } + ] } ] }, "liveHosts": { - "title": "Hosts", - "refreshInterval": 30, - "template": "tables", + "template": "page", "components": [ { - "type": "actionbar", - "config": { - "components": [ - "filter", - "acknowledge", - "downtime", - "recheck", - "more", - "search-filter" - ], - "tableId": [0] - } - }, - { - "type": "table", - "config": { - "title": "Hosts", - "tableId": 0, - "cells": { - "text": [ - "Host", - "Address", - "Duration", - "Last check", - "Host status" - ], - "name": [ - "status_host", - "status_host_address", - "status_duration", - "status_last_check", - "status_host_status" - ] - }, - "headerFollow": true, - "inputSource": { - "service": "surveilStatus", - "config": { - "apiName": "hosts", - "filters": {} + "type": "panel", + "components": [ + { + "type": "title", + "attributes": { + "title": "Hosts" } }, - "isWrappable": false, - "noRepeatCell": "", - "checkColumn": true, - "containsActionBar": true - } + { + "type": "actionbar", + "attributes": { + "tableId": [ + 0 + ] + }, + "components": [ + { + "type": "actionbar-filter", + "attributes": { + "filters": [ + { + "location": "componentsConfig", + "content": "all" + }, + { + "location": "componentsConfig", + "content": "hostOk" + }, + { + "location": "componentsConfig", + "content": "hostNotOk" + } + ] + } + }, + { + "type": "actionbar-acknowledge", + "attributes": {} + }, + { + "type": "actionbar-downtime", + "attributes": {} + }, + { + "type": "actionbar-recheck", + "attributes": {} + }, + { + "type": "actionbar-more", + "attributes": {} + }, + { + "type": "actionbar-search-filter", + "attributes": {} + } + ] + }, + { + "type": "table", + "attributes": { + "tableId": 0, + "refreshInterval": 30, + "cells": { + "text": [ + "Host", + "Address", + "Duration", + "Last check", + "Host status" + ], + "name": [ + "status_host", + "status_host_address", + "status_duration", + "status_last_check", + "status_host_status" + ] + }, + "headerFollow": true, + "inputSource": "hosts", + "isWrappable": false, + "noRepeatCell": "", + "checkColumn": true + } + } + ] } ] }, "liveServices": { - "title": "Services", - "refreshInterval": 30, - "template": "tables", + "template": "page", "components": [ { - "type": "actionbar", - "config": { - "components": [ - "filter", - "acknowledge", - "downtime", - "recheck", - "more", - "search-filter" - ], - "tableId": [0] - } - }, - { - "type": "table", - "config": { - "title": "Services", - "tableId": 0, - "cells": { - "text": [ - "Host", - "Service check", - "Duration", - "Last check" - ], - "name": [ - "status_host", - "status_service_check", - "status_duration", - "status_last_check" - ] - }, - "inputSource": { - "service": "surveilStatus", - "config": { - "apiName": "services", - "filters": {} + "type": "panel", + "components": [ + { + "type": "title", + "attributes": { + "title": "Services" } }, - "isWrappable": false, - "noRepeatCell": "host", - "headerFollow": true, - "containsActionBar": true, - "checkColumn": true - } + { + "type": "actionbar", + "attributes": { + "tableId": [ + 0 + ] + }, + "components": [ + { + "type": "actionbar-filter", + "attributes": { + "filters": [ + { + "location": "componentsConfig", + "content": "all" + }, + { + "location": "componentsConfig", + "content": "serviceOk" + }, + { + "location": "componentsConfig", + "content": "serviceNotOk" + } + ] + } + }, + { + "type": "actionbar-acknowledge", + "attributes": {} + }, + { + "type": "actionbar-downtime", + "attributes": {} + }, + { + "type": "actionbar-recheck", + "attributes": {} + }, + { + "type": "actionbar-more", + "attributes": {} + }, + { + "type": "actionbar-search-filter", + "attributes": {} + } + ] + }, + { + "type": "table", + "attributes": { + "tableId": 0, + "refreshInterval": 30, + "cells": { + "text": [ + "Host", + "Service check", + "Duration", + "Last check" + ], + "name": [ + "status_host", + "status_service_check", + "status_duration", + "status_last_check" + ] + }, + "headerFollow": true, + "inputSource": "services", + "isWrappable": false, + "checkColumn": true, + "noRepeatCell": "host" + } + } + ] } ] }, "liveEvents": { - "title": "Events", - "refreshInterval": 30, - "template": "tables", + "template": "page", "components": [ { - "type": "actionbar", - "config": { - "components": [ - "filter", - "more", - "search-filter" - ], - "tableId": [0] - } - }, - { - "type": "table", - "config": { - "title": "Hosts", - "tableId": 0, - "cells": { - "text": [ - "Event type", - "Output", - "Host name", - "Service", - "Time", - "Complete data" - ], - "name": [ - "status_event_event_type", - "status_event_output", - "status_event_host_name", - "status_event_service", - "status_event_time", - "status_event" - ] - }, - "headerFollow": true, - "inputSource": { - "service": "surveilStatus", - "config": { - "apiName": "events", - "filters": {} + "type": "panel", + "components": [ + { + "type": "title", + "attributes": { + "title": "Events" } }, - "isWrappable": false, - "noRepeatCell": "", - "checkColumn": false, - "containsActionBar": false - } + { + "type": "actionbar", + "attributes": { + "tableId": [ + 0 + ] + }, + "components": [ + { + "type": "actionbar-filter", + "attributes": { + "filters": [ + { + "location": "componentsConfig", + "content": "all" + }, + { + "location": "componentsConfig", + "content": "allAlert" + }, + { + "location": "componentsConfig", + "content": "allNotification" + } + ] + } + }, + { + "type": "actionbar-more", + "attributes": {} + }, + { + "type": "actionbar-search-filter", + "attributes": {} + } + ] + }, + { + "type": "table", + "attributes": { + "refreshInterval": 30, + "tableId": 0, + "cells": { + "text": [ + "Event type", + "Output", + "Hostname", + "Service", + "Time", + "Complete data" + ], + "name": [ + "status_event_event_type", + "status_event_output", + "status_event_host_name", + "status_event_service", + "status_event_time", + "status_event" + ] + }, + "headerFollow": true, + "inputSource": "events", + "isWrappable": false, + "checkColumn": false, + "noRepeatCell": "" + } + } + ] } ] }, "host": { - "title": "Host", - "refreshInterval": 30, - "template": "host" + "template": "host", + "components": [ + { + "type": "panel", + "components": [ + { + "type": "host", + "components": [ + { + "type": "host-main", + "attributes": {} + }, + { + "type": "host-live", + "attributes": {} + }, + { + "type": "host-load", + "attributes": {} + }, + { + "type": "host-cpu", + "attributes": {} + }, + { + "type": "host-info", + "attributes": {} + }, + { + "type": "host-services-list", + "attributes": {} + } + ] + } + ] + } + ] }, "service": { - "title": "Service", - "refreshInterval": 30, - "template": "service" + "template": "service", + "components": [ + { + "type": "panel", + "components": [ + { + "type": "service", + "components": [ + { + "type": "service-main", + "attributes": {} + }, + { + "type": "service-live", + "attributes": {} + }, + { + "type": "service-info", + "attributes": {} + }, + { + "type": "service-graphs", + "attributes": {} + } + ] + } + ] + } + ], + "refreshInterval": 30 }, "drupal": { "title": "Drupal", diff --git a/app/components/datasource/datasource.js b/app/components/datasource/datasource.js new file mode 100644 index 0000000..24b6a73 --- /dev/null +++ b/app/components/datasource/datasource.js @@ -0,0 +1,193 @@ +'use strict'; + +angular.module('bansho.datasource', ['bansho.surveil']) + .value('tableGlobalConfig', {'cellToFieldsMap': {}, 'cellWrappableField': {}}) + + .service('datasource', ['$filter', 'surveilStatus', 'surveilQuery', 'componentsConfig', 'tableGlobalConfig', + function ($filter, surveilStatus, surveilQuery, componentsConfig, tableGlobalConfig) { + var providerServices = { + status: surveilStatus + }, + config = [], + data = [], + filteredData = [], + listeners = []; + + function notifyDataChanged(tableId) { + angular.forEach(listeners[tableId], function (callback) { + callback(filteredData[tableId], config[tableId].isCheckAll); + }); + } + + function filterData(tableId) { + filteredData[tableId] = $filter('filter')(data[tableId], config[tableId].searchFilter); + notifyDataChanged(tableId); + } + + function refreshTableData(tableId) { + var conf = config[tableId], + inputSource = componentsConfig.getInputSource(conf.inputSource), + filter = componentsConfig.getFilter(inputSource.filter).filter, + promise; + + if (config[tableId].queryFilter) { + filter = componentsConfig.mergeFilters([config[tableId].queryFilter, filter]); + } + + promise = providerServices[inputSource.provider].getData([], filter, inputSource.endpoint); + + promise.then(function (newData) { + data[tableId] = newData; + config[tableId].isCheckAll = false; + filterData(tableId); + }, function (error) { + throw new Error('getTableData : Query failed' + error); + }); + } + + return { + refreshTableData: refreshTableData, + addTable: function (tableId, conf) { + config[tableId] = conf; + config[tableId].requestFields = []; + angular.forEach(config[tableId].cells.name, function (cell) { + angular.forEach(tableGlobalConfig.cellToFieldsMap[cell], function (_value) { + config[tableId].requestFields.push(_value); + }); + }); + }, + getConfig: function (tableId) { + return config[tableId]; + }, + forEachCheckedEntry: function (tableId, callbackIsChecked) { + angular.forEach(filteredData[tableId], function (entry) { + if (entry.is_checked) { + callbackIsChecked(entry); + } + }); + + notifyDataChanged(tableId); + }, + registerDataChanged: function (tableId, callback) { + if (!listeners[tableId]) { + listeners[tableId] = []; + } + + listeners[tableId].push(callback); + }, + setAllCheckTable: function (tableId, isChecked) { + config[tableId].isCheckAll = isChecked; + angular.forEach(filteredData[tableId], function (entry) { + entry.is_checked = isChecked; + }); + + notifyDataChanged(tableId, isChecked); + }, + setSearchFilter: function (tableId, searchFilter) { + config[tableId].searchFilter = searchFilter; + filterData(tableId); + + notifyDataChanged(tableId); + }, + setQueryFilter: function (tableId, queryFilter) { + config[tableId].queryFilter = queryFilter; + refreshTableData(tableId); + } + }; + }]) + + .service('sharedData', ['$interval', 'surveilStatus', + function ($interval, surveilStatus) { + var sharedData = {}, + listeners = {}, + providers = { + 'nbHostsOpenProblems': function (key) { + surveilStatus.getNbHostOpenProblems().then(function (nbHostProblems) { + sharedData[key].value = nbHostProblems; + notifyListeners(key); + }); + }, + 'nbServicesOpenProblems': function (key) { + surveilStatus.getNbServiceOpenProblems().then(function (nbServiceProblems) { + sharedData[key].value = nbServiceProblems; + notifyListeners(key); + }); + }, + 'nbHosts': function (key) { + surveilStatus.getNbHosts().then(function (nbHosts) { + sharedData[key].value = nbHosts; + notifyListeners(key); + }); + + }, + 'nbServices': function (key) { + surveilStatus.getNbServices().then(function (nbServices) { + sharedData[key].value = nbServices; + notifyListeners(key); + }); + }, + 'nbServicesOpenProblemsOnly': function (key) { + surveilStatus.getNbServiceOpenProblemsOnly().then(function (nbServices) { + sharedData[key].value = nbServices; + notifyListeners(key); + }); + }, + 'nbServicesHostsOpenProblems': function (key) { + surveilStatus.getNbHostsProblems().then(function (nbHosts) { + surveilStatus.getNbServiceOpenProblemsOnly().then(function (nbServices) { + sharedData[key].value = nbHosts + nbServices; + notifyListeners(key); + }); + }); + }, + 'nbServicesHostsOpenProblemsDoubleCount': function (key) { + surveilStatus.getNbHostsProblems().then(function (nbHosts) { + surveilStatus.getNbServiceOpenProblems().then(function (nbServices) { + sharedData[key].value = nbHosts + nbServices; + notifyListeners(key); + }); + }); + } + }; + + var notifyListeners = function (key) { + angular.forEach(listeners[key], function (onChange) { + onChange(sharedData[key].value); + }); + }; + + return { + clear: function () { + angular.forEach(sharedData, function (provider) { + $interval.cancel(provider.promise); + }); + sharedData = {}; + listeners = {}; + }, + getData: function (key, interval, onChange) { + if (!sharedData[key]) { + sharedData[key] = { + interval: interval + }; + + listeners[key] = [ + onChange + ]; + + providers[key](key); + $interval(providers[key](key), interval); + } else { + listeners[key].push(onChange); + + if (sharedData[key].interval >= interval) { + sharedData[key].interval = interval; + $interval.cancel(sharedData[key].promise); + sharedData[key].promise = $interval(providers[key](key), interval); + } + + } + + return sharedData[key].value; + } + }; + }]); diff --git a/app/components/table/actionbar/actionbar.html b/app/components/directive/actionbar/actionbar.html similarity index 52% rename from app/components/table/actionbar/actionbar.html rename to app/components/directive/actionbar/actionbar.html index 2ad68de..69f2bf0 100644 --- a/app/components/table/actionbar/actionbar.html +++ b/app/components/directive/actionbar/actionbar.html @@ -1,4 +1,5 @@ diff --git a/app/components/directive/actionbar/actionbar.js b/app/components/directive/actionbar/actionbar.js new file mode 100644 index 0000000..d238582 --- /dev/null +++ b/app/components/directive/actionbar/actionbar.js @@ -0,0 +1,22 @@ +'use strict'; + +angular.module('bansho.actionbar', ['bansho.datasource', 'bansho.surveil', 'bansho.notifications']) + .directive('banshoActionbar', ['$compile', function ($compile) { + return { + restrict: 'E', + scope: { + options: '=' + }, + templateUrl: 'components/directive/actionbar/actionbar.html', + link: function (scope, element) { + scope.tableId = scope.options.attributes.tableId; + scope.components = scope.options.components; + + angular.forEach(scope.components, function (component) { + component.attributes.tableId = scope.tableId; + }); + + $compile(element.contents())(scope); + } + }; + }]); diff --git a/app/components/table/actionbar/component_acknowledge/acknowledge.html b/app/components/directive/actionbar/component_acknowledge/acknowledge.html similarity index 100% rename from app/components/table/actionbar/component_acknowledge/acknowledge.html rename to app/components/directive/actionbar/component_acknowledge/acknowledge.html diff --git a/app/components/table/actionbar/component_acknowledge/acknowledge.js b/app/components/directive/actionbar/component_acknowledge/acknowledge.js similarity index 50% rename from app/components/table/actionbar/component_acknowledge/acknowledge.js rename to app/components/directive/actionbar/component_acknowledge/acknowledge.js index a16237c..9348409 100644 --- a/app/components/table/actionbar/component_acknowledge/acknowledge.js +++ b/app/components/directive/actionbar/component_acknowledge/acknowledge.js @@ -1,38 +1,32 @@ 'use strict'; -angular.module('bansho.table.actionbar') +angular.module('bansho.actionbar') .directive('banshoActionbarAcknowledge', [function () { return { restrict: 'E', - templateUrl: 'components/table/actionbar/component_acknowledge/acknowledge.html', + templateUrl: 'components/directive/actionbar/component_acknowledge/acknowledge.html', scope: { - tableId: '=' + options: '=' }, - controller: ['$scope', 'tables', 'surveilActions', 'notifications', - function ($scope, tables, surveilActions, notifications) { + controller: ['$scope', 'datasource', 'surveilActions', 'notifications', + function ($scope, datasource, surveilActions, notifications) { $scope.isAcknowledgeFormShown = false; $scope.switchAcknowledgeFormShown = function () { $scope.isAcknowledgeFormShown = !$scope.isAcknowledgeFormShown; }; $scope.acknowledgeProblems = function () { - angular.forEach($scope.tableId, function (tableId) { - tables.forEachCheckedEntry(tableId, function (entry) { - var service_description; - - if ('description' in entry) { - service_description = entry.description; - } - - surveilActions.acknowledge(entry.host_name, service_description, $scope.attrs).then(function (data) { - notifications.push('success', 'Acknowledgement', 'Acknowledged ' + entry.host_name); + angular.forEach($scope.options.attributes.tableId, function (tableId) { + datasource.forEachCheckedEntry(tableId, function (entry) { + surveilActions.acknowledge(entry.host_host_name, entry.service_service_description, $scope.attrs).then(function (data) { + notifications.push('success', 'Acknowledgement', 'Acknowledged ' + entry.host_host_name + ' ' + entry.service_service_description); }, function (error) { - notifications.push('error', 'Acknowledgement', 'Could not acknowledge ' + entry.host_name); + notifications.push('error', 'Acknowledgement', 'Could not acknowledge ' + entry.host_host_name + ' ' + entry.service_service_description); }); }); - tables.setAllCheckTable(tableId, false); + datasource.setAllCheckTable(tableId, false); }); $scope.isAcknowledgeFormShown = false; diff --git a/app/components/table/actionbar/component_downtime/downtime.html b/app/components/directive/actionbar/component_downtime/downtime.html similarity index 100% rename from app/components/table/actionbar/component_downtime/downtime.html rename to app/components/directive/actionbar/component_downtime/downtime.html diff --git a/app/components/directive/actionbar/component_downtime/downtime.js b/app/components/directive/actionbar/component_downtime/downtime.js new file mode 100644 index 0000000..2865a93 --- /dev/null +++ b/app/components/directive/actionbar/component_downtime/downtime.js @@ -0,0 +1,39 @@ +'use strict'; + +angular.module('bansho.actionbar') + .directive('banshoActionbarDowntime', [function () { + return { + restrict: 'E', + templateUrl: 'components/directive/actionbar/component_downtime/downtime.html', + scope: { + options: '=' + }, + controller: ['$scope', 'datasource', 'surveilActions', 'notifications', + function ($scope, datasource, surveilActions, notifications) { + $scope.tableId = $scope.options.attributes.tableId; + + $scope.isDowntimeFormShown = false; + $scope.switchDowntimeFormShown = function () { + $scope.isDowntimeFormShown = !$scope.isDowntimeFormShown; + }; + + $scope.sendDowntime = function () { + angular.forEach($scope.options.attributes.tableId, function (tableId) { + datasource.forEachCheckedEntry(tableId, function (entry) { + surveilActions.downtime(entry.host_host_name, entry.service_service_description, $scope.attrs).then(function (data) { + notifications.push('success', 'Downtime', 'Added downtime for ' + entry.host_host_name + ' ' + entry.service_service_description); + }, + function (error) { + notifications.push('error', 'Downtime', 'Could not add downtime for ' + entry.host_host_name + ' ' + entry.service_service_description); + }); + }); + + datasource.setAllCheckTable(tableId, false); + }); + + $scope.isDowntimeFormShown = false; + }; + } + ] + }; + }]); diff --git a/app/components/table/actionbar/component_filter/filter.html b/app/components/directive/actionbar/component_filter/filter.html similarity index 51% rename from app/components/table/actionbar/component_filter/filter.html rename to app/components/directive/actionbar/component_filter/filter.html index d8c992e..3653d9b 100644 --- a/app/components/table/actionbar/component_filter/filter.html +++ b/app/components/directive/actionbar/component_filter/filter.html @@ -1,19 +1,19 @@ -
  • +
  • -
    + diff --git a/app/components/directive/actionbar/component_filter/filter.js b/app/components/directive/actionbar/component_filter/filter.js new file mode 100644 index 0000000..30e020f --- /dev/null +++ b/app/components/directive/actionbar/component_filter/filter.js @@ -0,0 +1,49 @@ +'use strict'; + +angular.module('bansho.actionbar') + .directive('banshoActionbarFilter', ['componentsConfig', function (componentsConfig) { + return { + restrict: 'E', + scope: { + options: '=' + }, + templateUrl: 'components/directive/actionbar/component_filter/filter.html', + controller: ['$scope', 'datasource', function ($scope, datasource) { + $scope.tableId = $scope.options.attributes.tableId; + + $scope.filters = []; + angular.forEach($scope.options.attributes.filters, function (filter) { + switch (filter.location) { + case 'inline': + $scope.filters.push(filter.content); + break; + case 'componentsConfig': + $scope.filters.push( + componentsConfig.getFilter( + filter.content + ) + ); + break; + } + }); + + $scope.isShown = false; + + $scope.activeFilter = $scope.filters[0]; + + $scope.components = $scope.options.components; + $scope.switchFilterFormShown = function () { + $scope.isShown = !$scope.isShown; + }; + + $scope.activateFilter = function (item) { + $scope.activeFilter = $scope.filters[item]; + + angular.forEach($scope.tableId, function (tableId) { + datasource.setQueryFilter(tableId, $scope.activeFilter.filter); + }); + $scope.isShown = false; + }; + }] + }; + }]); diff --git a/app/components/table/actionbar/component_more/more.html b/app/components/directive/actionbar/component_more/more.html similarity index 100% rename from app/components/table/actionbar/component_more/more.html rename to app/components/directive/actionbar/component_more/more.html diff --git a/app/components/directive/actionbar/component_more/more.js b/app/components/directive/actionbar/component_more/more.js new file mode 100644 index 0000000..5a31bbf --- /dev/null +++ b/app/components/directive/actionbar/component_more/more.js @@ -0,0 +1,13 @@ +'use strict'; + +angular.module('bansho.actionbar') + .directive('banshoActionbarMore', [function () { + return { + restrict: 'E', + scope: { + 'tableId': '=' + }, + templateUrl: 'components/directive/actionbar/component_more/more.html', + controller: ['$scope', 'datasource', function ($scope, datasource) {}] + }; + }]); diff --git a/app/components/table/actionbar/component_recheck/recheck.html b/app/components/directive/actionbar/component_recheck/recheck.html similarity index 100% rename from app/components/table/actionbar/component_recheck/recheck.html rename to app/components/directive/actionbar/component_recheck/recheck.html diff --git a/app/components/directive/actionbar/component_recheck/recheck.js b/app/components/directive/actionbar/component_recheck/recheck.js new file mode 100644 index 0000000..182128c --- /dev/null +++ b/app/components/directive/actionbar/component_recheck/recheck.js @@ -0,0 +1,30 @@ +'use strict'; + +angular.module('bansho.actionbar') + .directive('banshoActionbarRecheck', [function () { + return { + restrict: 'EA', + scope: { + options: '=' + }, + templateUrl: 'components/directive/actionbar/component_recheck/recheck.html', + controller: ['$scope', 'datasource', 'surveilActions', 'notifications', + function ($scope, datasource, surveilActions, notifications) { + $scope.sendRecheck = function () { + angular.forEach($scope.options.attributes.tableId, function (tableId) { + datasource.forEachCheckedEntry(tableId, function (entry) { + surveilActions.recheck(entry.host_host_name, entry.service_service_description).then(function (data) { + notifications.push('success', 'Recheck', 'Scheduled recheck for ' + entry.host_host_name + ' ' + entry.service_service_description); + }, + function (error) { + notifications.push('error', 'Recheck', 'Could not schedule recheck for ' + entry.host_host_name + ' ' + entry.service_service_description); + }); + }); + + datasource.setAllCheckTable(tableId, false); + }); + }; + } + ] + }; + }]); diff --git a/app/components/table/actionbar/component_search_filter/search_filter.html b/app/components/directive/actionbar/component_search_filter/search_filter.html similarity index 100% rename from app/components/table/actionbar/component_search_filter/search_filter.html rename to app/components/directive/actionbar/component_search_filter/search_filter.html diff --git a/app/components/directive/actionbar/component_search_filter/search_filter.js b/app/components/directive/actionbar/component_search_filter/search_filter.js new file mode 100644 index 0000000..e5f3ee8 --- /dev/null +++ b/app/components/directive/actionbar/component_search_filter/search_filter.js @@ -0,0 +1,19 @@ +'use strict'; + +angular.module('bansho.actionbar') + .directive('banshoActionbarSearchFilter', [function () { + return { + restrict: 'E', + scope: { + options: '=' + }, + templateUrl: 'components/directive/actionbar/component_search_filter/search_filter.html', + controller: ['$scope', 'datasource', function ($scope, datasource) { + $scope.searchFilterChange = function () { + angular.forEach($scope.options.attributes.tableId, function (tableId) { + datasource.setSearchFilter(tableId, $scope.searchFilter); + }); + }; + }] + }; + }]); diff --git a/app/components/directive/directive.js b/app/components/directive/directive.js new file mode 100644 index 0000000..a784062 --- /dev/null +++ b/app/components/directive/directive.js @@ -0,0 +1,11 @@ +'use strict'; + +angular.module('bansho.directive', [ + 'bansho.actionbar', + 'bansho.host', + 'bansho.service', + 'bansho.table', + 'bansho.tabpanel', + 'bansho.tactical', + 'bansho.title' +]); diff --git a/app/components/directive/host/host.html b/app/components/directive/host/host.html new file mode 100644 index 0000000..2683465 --- /dev/null +++ b/app/components/directive/host/host.html @@ -0,0 +1,6 @@ +
    +
    + +
    +
    + diff --git a/app/components/directive/host/host.js b/app/components/directive/host/host.js new file mode 100644 index 0000000..8c32f2f --- /dev/null +++ b/app/components/directive/host/host.js @@ -0,0 +1,37 @@ +'use strict'; + +angular.module('bansho.host', ['bansho.datasource']) + + .directive('banshoHost', function () { + return { + restrict: 'E', + scope: { + options: '=' + }, + templateUrl: 'components/directive/host/host.html', + controller: ['$scope', 'pageParams', 'surveilStatus', 'iframeUrl', + function ($scope, pageParams, surveilStatus, iframeUrl) { + var hostname = pageParams.hostname; + + $scope.param = {}; + surveilStatus.getHost(hostname).then(function (data) { + surveilStatus.getService(hostname).then(function(services) { + $scope.param.host = data[0]; + $scope.param.host.services = []; + angular.forEach(services, function (service) { + if (service.service_description === 'cpu') { + $scope.param.host.cpu = service; + } else if (service.service_description === 'load') { + $scope.param.host.load = service; + $scope.param.host.load.iframeUrl = iframeUrl.getIFrameUrl("metric_load1", hostname, "load"); + } else { + $scope.param.host.services.push(service); + } + }); + }); + }); + + $scope.components = $scope.options.components; + }] + }; + }); diff --git a/app/components/directive/host/host_cpu/host_cpu.html b/app/components/directive/host/host_cpu/host_cpu.html new file mode 100644 index 0000000..71e99ca --- /dev/null +++ b/app/components/directive/host/host_cpu/host_cpu.html @@ -0,0 +1,15 @@ +
    +

    Cpu

    + + + + + + + + + + + +
    State {{param.host.cpu.state}}
    Output{{param.host.cpu.plugin_output}}
    +
    diff --git a/app/components/directive/host/host_cpu/host_cpu.js b/app/components/directive/host/host_cpu/host_cpu.js new file mode 100644 index 0000000..5a28eca --- /dev/null +++ b/app/components/directive/host/host_cpu/host_cpu.js @@ -0,0 +1,12 @@ +'use strict'; + +angular.module('bansho.host') + .directive('banshoHostCpu', function () { + return { + restrict: 'E', + templateUrl: 'components/directive/host/host_cpu/host_cpu.html', + link: function (scope) { + scope.param = scope.$parent.param; + } + }; + }); diff --git a/app/components/directive/host/host_info/host_info.html b/app/components/directive/host/host_info/host_info.html new file mode 100644 index 0000000..5bd93c6 --- /dev/null +++ b/app/components/directive/host/host_info/host_info.html @@ -0,0 +1,35 @@ +
    +

    Info

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Last check{{param.host.host_last_check | timeElapsed}}
    Check period{{param.host.config_host_check_period}}
    Notification period{{param.host.config_host_notification_period}}
    Active checks{{param.host.config_host_active_checks}}
    Notifications{{param.host.config_host_notifications_enabled}}
    Event Handler{{param.host.config_host_event_handler_enabled}}
    Flag detection{{param.host.config_host_flap_detection_enabled}}
    +
    diff --git a/app/components/directive/host/host_info/host_info.js b/app/components/directive/host/host_info/host_info.js new file mode 100644 index 0000000..a310940 --- /dev/null +++ b/app/components/directive/host/host_info/host_info.js @@ -0,0 +1,12 @@ +'use strict'; + +angular.module('bansho.host') + .directive('banshoHostInfo', function () { + return { + restrict: 'E', + templateUrl: 'components/directive/host/host_info/host_info.html', + link: function (scope) { + scope.param = scope.$parent.param; + } + }; + }); diff --git a/app/components/directive/host/host_live/host_live.html b/app/components/directive/host/host_live/host_live.html new file mode 100644 index 0000000..82ba2f9 --- /dev/null +++ b/app/components/directive/host/host_live/host_live.html @@ -0,0 +1,15 @@ +
    +

    Live status

    + + + + + + + + + + + +
    State {{param.host.host_state}}
    Output{{param.host.host_plugin_output}}
    +
    diff --git a/app/components/directive/host/host_live/host_live.js b/app/components/directive/host/host_live/host_live.js new file mode 100644 index 0000000..204b988 --- /dev/null +++ b/app/components/directive/host/host_live/host_live.js @@ -0,0 +1,12 @@ +'use strict'; + +angular.module('bansho.host') + .directive('banshoHostLive', function () { + return { + restrict: 'E', + templateUrl: 'components/directive/host/host_live/host_live.html', + link: function (scope) { + scope.param = scope.$parent.param; + } + }; + }); diff --git a/app/components/directive/host/host_load/host_load.html b/app/components/directive/host/host_load/host_load.html new file mode 100644 index 0000000..f675270 --- /dev/null +++ b/app/components/directive/host/host_load/host_load.html @@ -0,0 +1,16 @@ +
    +

    Load

    + + + + + + + + + + + + +
    State {{param.host.load.state}}
    Output{{param.host.load.plugin_output}}
    +
    diff --git a/app/components/directive/host/host_load/host_load.js b/app/components/directive/host/host_load/host_load.js new file mode 100644 index 0000000..b79fc3e --- /dev/null +++ b/app/components/directive/host/host_load/host_load.js @@ -0,0 +1,12 @@ +'use strict'; + +angular.module('bansho.host') + .directive('banshoHostLoad', function () { + return { + restrict: 'E', + templateUrl: 'components/directive/host/host_load/host_load.html', + link: function (scope) { + scope.param = scope.$parent.param; + } + }; + }); diff --git a/app/components/directive/host/host_main/host_main.html b/app/components/directive/host/host_main/host_main.html new file mode 100644 index 0000000..cd3a7ca --- /dev/null +++ b/app/components/directive/host/host_main/host_main.html @@ -0,0 +1,9 @@ +
    +
    +

    + {{param.host.host_host_name}} + (param.host.host_config_alias) + {{param.host.host_address}} +

    +
    +
    diff --git a/app/components/directive/host/host_main/host_main.js b/app/components/directive/host/host_main/host_main.js new file mode 100644 index 0000000..29c892c --- /dev/null +++ b/app/components/directive/host/host_main/host_main.js @@ -0,0 +1,12 @@ +'use strict'; + +angular.module('bansho.host') + .directive('banshoHostMain', function () { + return { + restrict: 'E', + templateUrl: 'components/directive/host/host_main/host_main.html', + link: function (scope) { + scope.param = scope.$parent.param; + } + }; + }); diff --git a/app/components/directive/host/host_services_list/host_services_list.html b/app/components/directive/host/host_services_list/host_services_list.html new file mode 100644 index 0000000..7f7121f --- /dev/null +++ b/app/components/directive/host/host_services_list/host_services_list.html @@ -0,0 +1,19 @@ +
    +

    Services

    + + + + + + + + + + + + + + +
    Service descriptionAcknowledgedState
    {{service.service_service_description}} + {{service.service_acknowledged ? "Yes" : "No"}}{{service.service_state}}
    +
    diff --git a/app/components/directive/host/host_services_list/host_services_list.js b/app/components/directive/host/host_services_list/host_services_list.js new file mode 100644 index 0000000..c5474f2 --- /dev/null +++ b/app/components/directive/host/host_services_list/host_services_list.js @@ -0,0 +1,12 @@ +'use strict'; + +angular.module('bansho.host') + .directive('banshoHostServicesList', function () { + return { + restrict: 'E', + templateUrl: 'components/directive/host/host_services_list/host_services_list.html', + link: function (scope) { + scope.param = scope.$parent.param; + } + }; + }); diff --git a/app/components/directive/service/service.html b/app/components/directive/service/service.html new file mode 100644 index 0000000..ece8d6e --- /dev/null +++ b/app/components/directive/service/service.html @@ -0,0 +1,5 @@ +
    +
    + +
    +
    diff --git a/app/components/directive/service/service.js b/app/components/directive/service/service.js new file mode 100644 index 0000000..a5f0c86 --- /dev/null +++ b/app/components/directive/service/service.js @@ -0,0 +1,32 @@ +'use strict'; + +angular.module('bansho.service', ['bansho.datasource']) + + .directive('banshoService', function () { + return { + restrict: 'E', + scope: { + options: '=' + }, + templateUrl: 'components/directive/service/service.html', + controller: ['$scope', 'pageParams', 'surveilStatus', 'iframeUrl', + function ($scope, pageParams, surveilStatus, iframeUrl) { + var hostname = pageParams.host_name, + serviceDescription = pageParams.service_description; + + $scope.param = {}; + surveilStatus.getService(hostname, serviceDescription).then(function (data) { + $scope.param.service = data[0]; + surveilStatus.getServiceMetricNames(hostname, serviceDescription).then(function(metric_names) { + $scope.param.service.iframeUrls = {}; + angular.forEach(metric_names, function (metric) { + var metricName = metric.metric_name.substr(7); + $scope.param.service.iframeUrls[metricName] = iframeUrl.getIFrameUrl(metric.metric_name, hostname, serviceDescription); + }); + }); + }); + + $scope.components = $scope.options.components; + }] + }; + }); diff --git a/app/components/service/service_graphs/service_graphs.html b/app/components/directive/service/service_graphs/service_graphs.html similarity index 57% rename from app/components/service/service_graphs/service_graphs.html rename to app/components/directive/service/service_graphs/service_graphs.html index 6c56f51..1814901 100644 --- a/app/components/service/service_graphs/service_graphs.html +++ b/app/components/directive/service/service_graphs/service_graphs.html @@ -1,4 +1,4 @@ -
    +

    Graph - {{metric}}

    diff --git a/app/components/directive/service/service_graphs/service_graphs.js b/app/components/directive/service/service_graphs/service_graphs.js new file mode 100644 index 0000000..c996153 --- /dev/null +++ b/app/components/directive/service/service_graphs/service_graphs.js @@ -0,0 +1,9 @@ +'use strict'; + +angular.module('bansho.service') + .directive('banshoServiceGraphs', function () { + return { + restrict: 'E', + templateUrl: 'components/directive/service/service_graphs/service_graphs.html' + }; + }); diff --git a/app/components/service/service_info/service_info.html b/app/components/directive/service/service_info/service_info.html similarity index 50% rename from app/components/service/service_info/service_info.html rename to app/components/directive/service/service_info/service_info.html index 8c165b1..29eaa56 100644 --- a/app/components/service/service_info/service_info.html +++ b/app/components/directive/service/service_info/service_info.html @@ -1,18 +1,18 @@ -
    +

    Info

    - + - + - +
    Last check{{service.last_check|timeElapsed}}{{param.service.service_last_check|timeElapsed}}
    Last state change{{service.last_state_change|timeElapsed}}{{param.service.service_last_state_change|timeElapsed}}
    Acknowledged{{isAcknowledged}}{{param.service.service_acknowledged ? "Yes" : "No"}}
    diff --git a/app/components/directive/service/service_info/service_info.js b/app/components/directive/service/service_info/service_info.js new file mode 100644 index 0000000..92145ec --- /dev/null +++ b/app/components/directive/service/service_info/service_info.js @@ -0,0 +1,9 @@ +'use strict'; + +angular.module('bansho.service') + .directive('banshoServiceInfo', function () { + return { + restrict: 'E', + templateUrl: 'components/directive/service/service_info/service_info.html' + }; + }); diff --git a/app/components/directive/service/service_live/service_live.html b/app/components/directive/service/service_live/service_live.html new file mode 100644 index 0000000..fea7d5e --- /dev/null +++ b/app/components/directive/service/service_live/service_live.html @@ -0,0 +1,15 @@ +
    +

    Status

    + + + + + + + + + + + +
    State {{param.service.service_state}}
    Output{{param.service.service_plugin_output}}
    +
    diff --git a/app/components/directive/service/service_live/service_live.js b/app/components/directive/service/service_live/service_live.js new file mode 100644 index 0000000..372c0d1 --- /dev/null +++ b/app/components/directive/service/service_live/service_live.js @@ -0,0 +1,9 @@ +'use strict'; + +angular.module('bansho.service') + .directive('banshoServiceLive', function () { + return { + restrict: 'E', + templateUrl: 'components/directive/service/service_live/service_live.html' + }; + }); diff --git a/app/components/directive/service/service_main/service_main.html b/app/components/directive/service/service_main/service_main.html new file mode 100644 index 0000000..a8ccc74 --- /dev/null +++ b/app/components/directive/service/service_main/service_main.html @@ -0,0 +1,7 @@ +
    +

    {{param.service.service_service_description}} + + {{param.service.host_host_name}} + +

    +
    diff --git a/app/components/directive/service/service_main/service_main.js b/app/components/directive/service/service_main/service_main.js new file mode 100644 index 0000000..5e17623 --- /dev/null +++ b/app/components/directive/service/service_main/service_main.js @@ -0,0 +1,12 @@ +'use strict'; + +angular.module('bansho.service') + .directive('banshoServiceMain', function () { + return { + restrict: 'E', + templateUrl: 'components/directive/service/service_main/service_main.html', + link: function (scope) { + scope.param = scope.$parent.param; + } + }; + }); diff --git a/app/components/directive/service/service_metrics/service_metrics.html b/app/components/directive/service/service_metrics/service_metrics.html new file mode 100644 index 0000000..40918a8 --- /dev/null +++ b/app/components/directive/service/service_metrics/service_metrics.html @@ -0,0 +1,3 @@ +
    +

    Metrics

    +
    diff --git a/app/components/service/service_metrics/service_metrics.js b/app/components/directive/service/service_metrics/service_metrics.js similarity index 55% rename from app/components/service/service_metrics/service_metrics.js rename to app/components/directive/service/service_metrics/service_metrics.js index 489cdbc..6c734b9 100644 --- a/app/components/service/service_metrics/service_metrics.js +++ b/app/components/directive/service/service_metrics/service_metrics.js @@ -1,17 +1,12 @@ 'use strict'; angular.module('bansho.service.metrics', []) - - .controller('ServiceMetricsCtrl', ['$scope', function ($scope) { - angular.noop(); - }]) - .directive('banshoServiceMetrics', function () { return { restrict: 'E', - scope: { - service: '=service' - }, - templateUrl: 'components/service/service_metrics/service_metrics.html' + templateUrl: 'components/service/service_metrics/service_metrics.html', + link: function (scope) { + scope.param = scope.$parent.param; + } }; }); diff --git a/app/components/directive/table/cell_status_duration/cell_status_duration.html b/app/components/directive/table/cell_status_duration/cell_status_duration.html new file mode 100644 index 0000000..eaa2e18 --- /dev/null +++ b/app/components/directive/table/cell_status_duration/cell_status_duration.html @@ -0,0 +1,3 @@ + + + diff --git a/app/components/table/cell_status_duration/cell_status_duration.js b/app/components/directive/table/cell_status_duration/cell_status_duration.js similarity index 100% rename from app/components/table/cell_status_duration/cell_status_duration.js rename to app/components/directive/table/cell_status_duration/cell_status_duration.js diff --git a/app/components/table/cell_status_event/cell_status_event.html b/app/components/directive/table/cell_status_event/cell_status_event.html similarity index 100% rename from app/components/table/cell_status_event/cell_status_event.html rename to app/components/directive/table/cell_status_event/cell_status_event.html diff --git a/app/components/table/cell_status_event/cell_status_event.js b/app/components/directive/table/cell_status_event/cell_status_event.js similarity index 75% rename from app/components/table/cell_status_event/cell_status_event.js rename to app/components/directive/table/cell_status_event/cell_status_event.js index b734063..c605c61 100644 --- a/app/components/table/cell_status_event/cell_status_event.js +++ b/app/components/directive/table/cell_status_event/cell_status_event.js @@ -9,19 +9,19 @@ angular.module('bansho.table.cell_status_event', ['bansho.table']) }; var shownOutput = { - 'attempts': true, - 'contact': true, - 'notification_method': true, - 'notification_type': true, - 'state': true, - 'state_type': true + 'event_attempts': true, + 'event_contact': true, + 'event_notification_method': true, + 'event_notification_type': true, + 'event_state': true, + 'event_state_type': true }; $scope.filter = function (entry) { var result = {}; angular.forEach(entry, function(value, key) { if (shownOutput[key]) { - result[key] = value; + result[key.substring(6)] = value; } }); return result; diff --git a/app/components/directive/table/cell_status_event_event_type/cell_status_event_event_type.html b/app/components/directive/table/cell_status_event_event_type/cell_status_event_event_type.html new file mode 100644 index 0000000..32730f1 --- /dev/null +++ b/app/components/directive/table/cell_status_event_event_type/cell_status_event_event_type.html @@ -0,0 +1,3 @@ + +

    {{entry.event_event_type}}

    + diff --git a/app/components/table/cell_status_event_event_type/cell_status_event_event_type.js b/app/components/directive/table/cell_status_event_event_type/cell_status_event_event_type.js similarity index 100% rename from app/components/table/cell_status_event_event_type/cell_status_event_event_type.js rename to app/components/directive/table/cell_status_event_event_type/cell_status_event_event_type.js diff --git a/app/components/directive/table/cell_status_event_host_name/cell_status_event_host_name.html b/app/components/directive/table/cell_status_event_host_name/cell_status_event_host_name.html new file mode 100644 index 0000000..d7f7007 --- /dev/null +++ b/app/components/directive/table/cell_status_event_host_name/cell_status_event_host_name.html @@ -0,0 +1,3 @@ + +

    {{entry.event_host_name}}

    + diff --git a/app/components/table/cell_status_event_host_name/cell_status_event_host_name.js b/app/components/directive/table/cell_status_event_host_name/cell_status_event_host_name.js similarity index 100% rename from app/components/table/cell_status_event_host_name/cell_status_event_host_name.js rename to app/components/directive/table/cell_status_event_host_name/cell_status_event_host_name.js diff --git a/app/components/table/cell_status_event_output/cell_status_event_output.html b/app/components/directive/table/cell_status_event_output/cell_status_event_output.html similarity index 60% rename from app/components/table/cell_status_event_output/cell_status_event_output.html rename to app/components/directive/table/cell_status_event_output/cell_status_event_output.html index 0136bd2..d14cf25 100644 --- a/app/components/table/cell_status_event_output/cell_status_event_output.html +++ b/app/components/directive/table/cell_status_event_output/cell_status_event_output.html @@ -1,3 +1,3 @@ -

    {{entry.output}}

    +

    {{entry.event_output}}

    diff --git a/app/components/table/cell_status_event_output/cell_status_event_output.js b/app/components/directive/table/cell_status_event_output/cell_status_event_output.js similarity index 100% rename from app/components/table/cell_status_event_output/cell_status_event_output.js rename to app/components/directive/table/cell_status_event_output/cell_status_event_output.js diff --git a/app/components/directive/table/cell_status_event_service/cell_status_event_service.html b/app/components/directive/table/cell_status_event_service/cell_status_event_service.html new file mode 100644 index 0000000..3c02f4e --- /dev/null +++ b/app/components/directive/table/cell_status_event_service/cell_status_event_service.html @@ -0,0 +1,3 @@ + +

    {{entry.event_service_description}}

    + diff --git a/app/components/table/cell_status_event_service/cell_status_event_service.js b/app/components/directive/table/cell_status_event_service/cell_status_event_service.js similarity index 100% rename from app/components/table/cell_status_event_service/cell_status_event_service.js rename to app/components/directive/table/cell_status_event_service/cell_status_event_service.js diff --git a/app/components/directive/table/cell_status_event_time/cell_status_event_time.html b/app/components/directive/table/cell_status_event_time/cell_status_event_time.html new file mode 100644 index 0000000..9c4cc03 --- /dev/null +++ b/app/components/directive/table/cell_status_event_time/cell_status_event_time.html @@ -0,0 +1,3 @@ + + + diff --git a/app/components/table/cell_status_event_time/cell_status_event_time.js b/app/components/directive/table/cell_status_event_time/cell_status_event_time.js similarity index 100% rename from app/components/table/cell_status_event_time/cell_status_event_time.js rename to app/components/directive/table/cell_status_event_time/cell_status_event_time.js diff --git a/app/components/table/cell_status_host/cell_status_host.html b/app/components/directive/table/cell_status_host/cell_status_host.html similarity index 77% rename from app/components/table/cell_status_host/cell_status_host.html rename to app/components/directive/table/cell_status_host/cell_status_host.html index c41dc0c..58fd5b4 100644 --- a/app/components/table/cell_status_host/cell_status_host.html +++ b/app/components/directive/table/cell_status_host/cell_status_host.html @@ -1,3 +1,3 @@ - {{entry.host_name}} + {{entry.host_host_name}} diff --git a/app/components/table/cell_status_host/cell_status_host.js b/app/components/directive/table/cell_status_host/cell_status_host.js similarity index 88% rename from app/components/table/cell_status_host/cell_status_host.js rename to app/components/directive/table/cell_status_host/cell_status_host.js index 08b8aa1..ddf779c 100644 --- a/app/components/table/cell_status_host/cell_status_host.js +++ b/app/components/directive/table/cell_status_host/cell_status_host.js @@ -17,6 +17,6 @@ angular.module('bansho.table.cell_status_host', ['bansho.table']) }]) .run(['tableGlobalConfig', function (tableGlobalConfig) { - tableGlobalConfig.cellToFieldsMap.status_host = ['host_state', 'host_name']; + tableGlobalConfig.cellToFieldsMap.status_host = ['state', 'host_name']; tableGlobalConfig.cellWrappableField.status_host = 'host_name'; }]); diff --git a/app/components/table/cell_status_host_address/cell_status_host_address.html b/app/components/directive/table/cell_status_host_address/cell_status_host_address.html similarity index 57% rename from app/components/table/cell_status_host_address/cell_status_host_address.html rename to app/components/directive/table/cell_status_host_address/cell_status_host_address.html index f40c7c2..ee275b3 100644 --- a/app/components/table/cell_status_host_address/cell_status_host_address.html +++ b/app/components/directive/table/cell_status_host_address/cell_status_host_address.html @@ -1,3 +1,3 @@ - {{entry.address}} + {{entry.host_address}} diff --git a/app/components/table/cell_status_host_address/cell_status_host_address.js b/app/components/directive/table/cell_status_host_address/cell_status_host_address.js similarity index 100% rename from app/components/table/cell_status_host_address/cell_status_host_address.js rename to app/components/directive/table/cell_status_host_address/cell_status_host_address.js diff --git a/app/components/table/cell_status_host_status/cell_status_host_status.html b/app/components/directive/table/cell_status_host_status/cell_status_host_status.html similarity index 100% rename from app/components/table/cell_status_host_status/cell_status_host_status.html rename to app/components/directive/table/cell_status_host_status/cell_status_host_status.html diff --git a/app/components/table/cell_status_host_status/cell_status_host_status.js b/app/components/directive/table/cell_status_host_status/cell_status_host_status.js similarity index 100% rename from app/components/table/cell_status_host_status/cell_status_host_status.js rename to app/components/directive/table/cell_status_host_status/cell_status_host_status.js diff --git a/app/components/directive/table/cell_status_last_check/cell_status_last_check.html b/app/components/directive/table/cell_status_last_check/cell_status_last_check.html new file mode 100644 index 0000000..ec5b9a9 --- /dev/null +++ b/app/components/directive/table/cell_status_last_check/cell_status_last_check.html @@ -0,0 +1,3 @@ + + + diff --git a/app/components/table/cell_status_last_check/cell_status_last_check.js b/app/components/directive/table/cell_status_last_check/cell_status_last_check.js similarity index 100% rename from app/components/table/cell_status_last_check/cell_status_last_check.js rename to app/components/directive/table/cell_status_last_check/cell_status_last_check.js diff --git a/app/components/directive/table/cell_status_service_check/cell_status_service_check.html b/app/components/directive/table/cell_status_service_check/cell_status_service_check.html new file mode 100644 index 0000000..75a3abf --- /dev/null +++ b/app/components/directive/table/cell_status_service_check/cell_status_service_check.html @@ -0,0 +1,8 @@ + +
    +
    + {{entry.service_service_description}} +
    +
    {{entry.service_plugin_output}}
    +
    + diff --git a/app/components/table/cell_status_service_check/cell_status_service_check.js b/app/components/directive/table/cell_status_service_check/cell_status_service_check.js similarity index 81% rename from app/components/table/cell_status_service_check/cell_status_service_check.js rename to app/components/directive/table/cell_status_service_check/cell_status_service_check.js index 2c047df..c39598f 100644 --- a/app/components/table/cell_status_service_check/cell_status_service_check.js +++ b/app/components/directive/table/cell_status_service_check/cell_status_service_check.js @@ -3,9 +3,9 @@ angular.module('bansho.table.cell_status_service_check', ['bansho.table']) .controller('CellStatusServiceCheckCtrl', ['$scope', function ($scope) { - if ($scope.entry.state === 'OK') { + if ($scope.entry.service_state === 'OK') { $scope.state = 'state--ok'; - } else if ($scope.entry.state === 'WARNING') { + } else if ($scope.entry.service_state === 'WARNING') { $scope.state = 'state--warning'; } else { $scope.state = 'state--error'; diff --git a/app/components/table/state_icon/state_icon.html b/app/components/directive/table/state_icon/state_icon.html similarity index 100% rename from app/components/table/state_icon/state_icon.html rename to app/components/directive/table/state_icon/state_icon.html diff --git a/app/components/directive/table/state_icon/state_icon.js b/app/components/directive/table/state_icon/state_icon.js new file mode 100644 index 0000000..b120ae1 --- /dev/null +++ b/app/components/directive/table/state_icon/state_icon.js @@ -0,0 +1,48 @@ +'use strict'; + +angular.module('bansho.table') + .directive('banshoHostStateIcon', function () { + return { + restrict: 'E', + scope: { + state: '=' + }, + templateUrl: 'components/directive/table/state_icon/state_icon.html', + controller: ['$scope', function ($scope) { + $scope.$watch('state', function (newValue) { + if ($scope.state === 'UP') { + $scope.stateClass = 'state--ok'; + } else if ($scope.state === 'WARNING') { + $scope.stateClass = 'state--warning'; + } else if ($scope.state === '') { + $scope.stateClass = ''; + } else { + $scope.stateClass = 'state--error'; + } + }); + }] + }; + }) + + .directive('banshoServiceStateIcon', function () { + return { + restrict: 'E', + scope: { + state: '=' + }, + templateUrl: 'components/directive/table/state_icon/state_icon.html', + controller: ['$scope', function ($scope) { + $scope.$watch('state', function (newValue) { + if ($scope.state === 'OK') { + $scope.stateClass = 'state--ok'; + } else if ($scope.state === 'WARNING') { + $scope.state = 'state--warning'; + } else if ($scope.state === '') { + $scope.stateClass = ''; + } else { + $scope.stateClass = 'state--error'; + } + }); + }] + }; + }); diff --git a/app/components/directive/table/table.html b/app/components/directive/table/table.html new file mode 100644 index 0000000..477b2f2 --- /dev/null +++ b/app/components/directive/table/table.html @@ -0,0 +1,40 @@ +
    +
    +

    tets{{title}}

    +
    + + + + + + + + + + + + + + + + + + + + + +
    + + + {{cellsText[i]}} + +
    + + + {{cellsText[i]}} + +
    + +
    +
    diff --git a/app/components/table/table.js b/app/components/directive/table/table.js similarity index 51% rename from app/components/table/table.js rename to app/components/directive/table/table.js index 5117d2b..53f7bcd 100644 --- a/app/components/table/table.js +++ b/app/components/directive/table/table.js @@ -1,8 +1,8 @@ 'use strict'; -angular.module('bansho.table', ['bansho.surveil', - 'bansho.utils.promiseManager', - 'bansho.table.actionbar', +angular.module('bansho.table', ['bansho.utils.promiseManager', + 'bansho.datasource', + 'bansho.actionbar', 'bansho.filters', 'bansho.table.cell_status_host', 'bansho.table.cell_status_event', @@ -18,166 +18,73 @@ angular.module('bansho.table', ['bansho.surveil', 'ngMaterial' ]) - .value('tableGlobalConfig', {'cellToFieldsMap': {}, 'cellWrappableField': {}}) - - .service('tables', ['$filter', 'surveilStatus', 'tableGlobalConfig', - function ($filter, surveilStatus, tableGlobalConfig) { - var inputSourceServices = { - surveilStatus: surveilStatus - }, - config = [], - data = [], - filteredData = [], - listeners = []; - - function notifyDataChanged(tableId) { - angular.forEach(listeners[tableId], function (callback) { - callback(filteredData[tableId], config[tableId].isCheckAll); - }); - } - - function filterData(tableId) { - filteredData[tableId] = $filter('filter')(data[tableId], config[tableId].searchFilter); - notifyDataChanged(tableId); - } - - return { - refreshTableData: function (tableId) { - var promise = inputSourceServices.surveilStatus.getTableData( - config[tableId].requestFields, config[tableId].inputSource.config); - promise.then(function (newData) { - data[tableId] = newData; - config[tableId].isCheckAll = false; - filterData(tableId); - }, function (error) { - throw new Error('getTableData : Query failed' + error); - }); - }, - addTable: function (tableId, conf) { - config[tableId] = conf; - config[tableId].requestFields = []; - angular.forEach(config[tableId].cells.name, function (cell) { - angular.forEach(tableGlobalConfig.cellToFieldsMap[cell], function (_value) { - config[tableId].requestFields.push(_value); - }); - }); - }, - getConfig: function (tableId) { - return config[tableId]; - }, - forEachCheckedEntry: function (tableId, callbackIsChecked) { - angular.forEach(filteredData[tableId], function (entry) { - if (entry.is_checked) { - callbackIsChecked(entry); - } - }); - - notifyDataChanged(tableId); - }, - registerDataChanged: function (tableId, callback) { - if (!listeners[tableId]) { - listeners[tableId] = []; - } - - listeners[tableId].push(callback); - }, - setAllCheckTable: function (tableId, isChecked) { - config[tableId].isCheckAll = isChecked; - angular.forEach(filteredData[tableId], function (entry) { - entry.is_checked = isChecked; - }); - - notifyDataChanged(tableId, isChecked); - }, - setSearchFilter: function (tableId, searchFilter) { - config[tableId].searchFilter = searchFilter; - filterData(tableId); - } - }; - }]) - - .controller('TableCtrl', ['$scope', '$interval', 'headerFollow', 'surveilStatus', 'tables', 'tableGlobalConfig', 'promisesManager', - function ($scope, $interval, headerFollow, surveilStatus, tables, tableGlobalConfig, - promisesManager) { - var conf = tables.getConfig($scope.tableId), - globalConfig = tableGlobalConfig, - i; - - if (conf.headerFollow) { - headerFollow.activate(); - } else { - headerFollow.deactivate(); - } - - $scope.cellsName = conf.cells.name; - $scope.cellsText = conf.cells.text; - $scope.cellIndexes = []; - for (i = 0; i < $scope.cellsName.length; i += 1) { - $scope.cellIndexes.push(i); - } - - $scope.onCheckChange = function() { - tables.setAllCheckTable($scope.tableId, $scope.isCheckAll); - }; - - tables.registerDataChanged($scope.tableId, function (data, isCheckAll) { - $scope.isCheckAll = isCheckAll; - $scope.entries = data; - }); - tables.refreshTableData($scope.tableId); - if (globalConfig.refreshInterval !== 0) { - promisesManager.addAjaxPromise( - $interval(function () { - tables.refreshTableData($scope.tableId); - }, globalConfig.refreshInterval) - ); - } - }]) - - .directive('banshoTable', ['$http', '$compile', 'tables', 'tableGlobalConfig', - function ($http, $compile, tables, tableGlobalConfig) { + .directive('banshoTable', ['datasource', 'tableGlobalConfig', + function (datasource, tableGlobalConfig) { return { restrict: 'E', scope: { - tableId: '=' + options: '=' }, - compile: function () { - return function (scope, element, attrs) { - var template = 'components/table/table.html', - conf = {}; + templateUrl: 'components/directive/table/table.html', + controller: ['$scope', '$interval', 'headerFollow', 'datasource', 'tableGlobalConfig', 'promisesManager', 'pageParams', + function ($scope, $interval, headerFollow, datasource, tableGlobalConfig, promisesManager, pageParams) { + var conf = {}, + refreshInterval = pageParams.refreshInterval ? pageParams.refreshInterval : 100000, + i; - if (!attrs.cellsText || !attrs.cellsName || !attrs.inputSource || !attrs.isWrappable) { - throw new Error(' "cells-text", "cells-name", "inputSource" and "is-wrappable" attributes must be defined'); - } + $scope.tableId = $scope.options.attributes.tableId; // Create table configuration - conf.cells = { 'text': [], 'name': [] }; - conf.cells.text = attrs.cellsText.split(','); - conf.cells.name = attrs.cellsName.split(','); + conf.title = $scope.options.attributes.title; - conf.inputSource = JSON.parse(attrs.inputSource); + conf.cells = {'text': [], 'name': []}; + conf.cells.text = $scope.options.attributes.cells.text; + conf.cells.name = $scope.options.attributes.cells.name; - conf.isWrappable = JSON.parse(attrs.isWrappable); - conf.noRepeatCell = attrs.noRepeatCell; - conf.headerFollow = scope.$eval(attrs.headerFollow); + conf.inputSource = $scope.options.attributes.inputSource; - tables.addTable(scope.tableId, conf); + conf.isWrappable = $scope.$eval($scope.options.attributes.isWrappable); + conf.noRepeatCell = $scope.options.attributes.noRepeatCell; - scope.checkColumn = scope.$eval(attrs.checkColumn); + datasource.addTable($scope.tableId, conf); - if (!!attrs.refreshInterval) { - tableGlobalConfig.refreshInterval = parseInt(attrs.refreshInterval * 1000, 10); + // Handle table layout + $scope.checkColumn = $scope.options.attributes.checkColumn; + + if ($scope.options.attributes.headerFollow) { + headerFollow.activate(); + } else { + headerFollow.deactivate(); } - $http.get(template, { cache: true }) - .success(function (data) { - var elem = $compile(data)(scope); - element.append(elem); - }); - }; - } + $scope.cellsName = conf.cells.name; + $scope.cellsText = conf.cells.text; + $scope.cellIndexes = []; + for (i = 0; i < $scope.cellsName.length; i += 1) { + $scope.cellIndexes.push(i); + } + + $scope.onCheckChange = function () { + datasource.setAllCheckTable($scope.tableId, $scope.isCheckAll); + }; + + datasource.registerDataChanged($scope.tableId, function (data, isCheckAll) { + $scope.isCheckAll = isCheckAll; + $scope.entries = data; + }); + datasource.refreshTableData($scope.tableId); + + if ($scope.options.attributes.refreshInterval && $scope.options.attributes.refreshInterval !== 0) { + promisesManager.addAjaxPromise( + $interval(function () { + datasource.refreshTableData($scope.tableId); + }, refreshInterval) + ); + } + }] }; - }]) + } + ]) .directive('banshoCell', ['$http', '$compile', function ($http, $compile) { return { @@ -188,7 +95,7 @@ angular.module('bansho.table', ['bansho.surveil', throw new Error(' "cell-name" attribute must be defined'); } - var template = 'components/table/cell_' + attrs.cellName + '/cell_' + attrs.cellName + '.html'; + var template = 'components/directive/table/cell_' + attrs.cellName + '/cell_' + attrs.cellName + '.html'; $http.get(template, { cache: true }) .success(function (data) { @@ -201,33 +108,20 @@ angular.module('bansho.table', ['bansho.surveil', }; }]) - .value('TableConfigObj', function (config) { - this.title = config.title; - this.tableId = config.tableId; - this.CellsText = config.cells.text.join(); - this.CellsName = config.cells.name.join(); - this.InputSource = config.inputSource; - this.IsWrappable = config.isWrappable; - this.ContainsActionBar = config.containsActionBar; - this.CheckColumn = config.checkColumn; - this.HeaderFollow = config.headerFollow; - this.NoRepeatCell = config.noRepeatCell; - }) - - .filter('wrappableStyle', ['tables', 'tableGlobalConfig', function (tables, tableGlobalConfig) { + .filter('wrappableStyle', ['datasource', 'tableGlobalConfig', function (datasource, tableGlobalConfig) { return function (input, scope) { var last = '', entry = {}, parent_found = false, class_name = ['', ''], i, - fieldToWrap = tableGlobalConfig.cellWrappableField[tables.getConfig(scope.tableId).noRepeatCell]; + fieldToWrap = tableGlobalConfig.cellWrappableField[datasource.getConfig(scope.tableId).noRepeatCell]; if (fieldToWrap === undefined) { return input; } - if (tables.getConfig(scope.tableId).isWrappable) { + if (datasource.getConfig(scope.tableId).isWrappable) { class_name = ['state--hasChild', 'state--isChild']; } @@ -256,12 +150,12 @@ angular.module('bansho.table', ['bansho.surveil', }; }]) - .filter('noRepeat', ['tables', 'tableGlobalConfig', function (tables, tableGlobalConfig) { + .filter('noRepeat', ['datasource', 'tableGlobalConfig', function (datasource, tableGlobalConfig) { return function (items, scope) { var newItems = [], previous, - fieldToCompare = tableGlobalConfig.cellWrappableField[tables.getConfig(scope.tableId).noRepeatCell], - newAttr = tables.getConfig(scope.tableId).noRepeatCell + "_additionnalClass"; + fieldToCompare = tableGlobalConfig.cellWrappableField[datasource.getConfig(scope.tableId).noRepeatCell], + newAttr = datasource.getConfig(scope.tableId).noRepeatCell + "_additionnalClass"; angular.forEach(items, function (item) { diff --git a/app/components/table/table_test.js b/app/components/directive/table/table_test.js similarity index 100% rename from app/components/table/table_test.js rename to app/components/directive/table/table_test.js diff --git a/app/components/directive/tabpanel/panel.html b/app/components/directive/tabpanel/panel.html new file mode 100644 index 0000000..6bb02df --- /dev/null +++ b/app/components/directive/tabpanel/panel.html @@ -0,0 +1,6 @@ +
    +
    + +
    +
    \ No newline at end of file diff --git a/app/components/directive/tabpanel/tabpanel.html b/app/components/directive/tabpanel/tabpanel.html new file mode 100644 index 0000000..63ee4c6 --- /dev/null +++ b/app/components/directive/tabpanel/tabpanel.html @@ -0,0 +1,17 @@ +
    + + +
    diff --git a/app/components/directive/tabpanel/tabpanel.js b/app/components/directive/tabpanel/tabpanel.js new file mode 100644 index 0000000..d8db625 --- /dev/null +++ b/app/components/directive/tabpanel/tabpanel.js @@ -0,0 +1,50 @@ +'use strict'; + +angular.module('bansho.tabpanel', []) + .directive('banshoTabpanel', ['sharedData', function (sharedData) { + return { + restrict: 'E', + templateUrl: 'components/directive/tabpanel/tabpanel.html', + scope: { + options: '=' + }, + link: function (scope) { + scope.navigation = scope.options.attributes.navigation; + + scope.currentPanel = 0; + scope.setIsShown = function (index) { + scope.currentPanel = index; + }; + + angular.forEach(scope.options.components, function (panel, index) { + panel.attributes.index = index; + }); + + angular.forEach(scope.options.attributes.navigation, function (panel, index) { + panel.right = sharedData.getData(panel.provider, 30000, function (data) { + panel.right = data; + }); + }); + } + }; + }]) + + .directive('banshoPanel', function () { + return { + restrict: 'E', + templateUrl: 'components/directive/tabpanel/panel.html', + scope: { + options: '=' + }, + link: function (scope) { + if (scope.$parent.$parent.currentPanel !== undefined) { + scope.parent = scope.$parent.$parent; + scope.index = scope.options.attributes.index; + } else { + scope.parent = {}; + scope.parent.currentPanel = 0; + scope.index = 0; + } + } + }; + }); diff --git a/app/components/tactical/_tactical.scss b/app/components/directive/tactical/_tactical.scss similarity index 100% rename from app/components/tactical/_tactical.scss rename to app/components/directive/tactical/_tactical.scss diff --git a/app/components/tactical/current_health/current_health.html b/app/components/directive/tactical/current_health/current_health.html similarity index 100% rename from app/components/tactical/current_health/current_health.html rename to app/components/directive/tactical/current_health/current_health.html diff --git a/app/components/tactical/current_health/current_health.js b/app/components/directive/tactical/current_health/current_health.js similarity index 80% rename from app/components/tactical/current_health/current_health.js rename to app/components/directive/tactical/current_health/current_health.js index 6b04f51..9e029bd 100644 --- a/app/components/tactical/current_health/current_health.js +++ b/app/components/directive/tactical/current_health/current_health.js @@ -10,6 +10,6 @@ angular.module('bansho.tactical.current_health', ['bansho.surveil', .directive('banshoCurrentHealth', function () { return { restrict: 'E', - templateUrl: 'components/tactical/current_health/current_health.html' + templateUrl: 'components/directive/tactical/current_health/current_health.html' }; }); diff --git a/app/components/tactical/current_health/current_health_test.js b/app/components/directive/tactical/current_health/current_health_test.js similarity index 100% rename from app/components/tactical/current_health/current_health_test.js rename to app/components/directive/tactical/current_health/current_health_test.js diff --git a/app/components/tactical/status_overview/status_overview.html b/app/components/directive/tactical/status_overview/status_overview.html similarity index 100% rename from app/components/tactical/status_overview/status_overview.html rename to app/components/directive/tactical/status_overview/status_overview.html diff --git a/app/components/tactical/status_overview/status_overview.js b/app/components/directive/tactical/status_overview/status_overview.js similarity index 75% rename from app/components/tactical/status_overview/status_overview.js rename to app/components/directive/tactical/status_overview/status_overview.js index 2feca23..4b306e1 100644 --- a/app/components/tactical/status_overview/status_overview.js +++ b/app/components/directive/tactical/status_overview/status_overview.js @@ -9,6 +9,6 @@ angular.module('bansho.tactical.status_overview', []) .directive('banshoStatusOverview', function () { return { restrict: 'E', - templateUrl: 'components/tactical/status_overview/status_overview.html' + templateUrl: 'components/directive/tactical/status_overview/status_overview.html' }; }); diff --git a/app/components/tactical/status_overview/status_overview_test.js b/app/components/directive/tactical/status_overview/status_overview_test.js similarity index 100% rename from app/components/tactical/status_overview/status_overview_test.js rename to app/components/directive/tactical/status_overview/status_overview_test.js diff --git a/app/components/directive/tactical/tactical.html b/app/components/directive/tactical/tactical.html new file mode 100644 index 0000000..0a2ea36 --- /dev/null +++ b/app/components/directive/tactical/tactical.html @@ -0,0 +1,19 @@ +
    +

    {{title}}

    +
    +
    +
    + +
    + +
    + +
    + +
    + +
    +
    +
    +
    + diff --git a/app/components/directive/tactical/tactical.js b/app/components/directive/tactical/tactical.js new file mode 100644 index 0000000..d155571 --- /dev/null +++ b/app/components/directive/tactical/tactical.js @@ -0,0 +1,51 @@ +'use strict'; + +angular.module('bansho.tactical', ['bansho.surveil', + 'bansho.tactical.status_overview', + 'bansho.tactical.current_health', + 'bansho.tactical.top_alert_producers' + ]) + + .directive('banshoTactical', function () { + return { + restrict: 'E', + templateUrl: 'components/directive/tactical/tactical.html', + scope: { + options: '=' + }, + controller: ['$scope', '$interval', 'surveilStatus', 'pageParams', 'sharedData', + function ($scope, $interval, surveilStatus, pageParams, sharedData) { + var refreshInterval = pageParams.refreshInterval ? pageParams.refreshInterval : 100000; + $scope.title = $scope.options.attributes.title; + + $scope.statusOverview = $scope.options.attributes.statusOverview; + $scope.currentHealth = $scope.options.attributes.currentHealth; + $scope.topAlertProducers = $scope.options.attributes.topAlertProducers; + + $scope.totalHosts = sharedData.getData('nbHosts', refreshInterval, function (data) { + $scope.totalHosts = data; + }); + + $scope.hostProblems = sharedData.getData('nbHostsOpenProblems', refreshInterval, function (data) { + $scope.hostProblems = data; + $scope.hostsRatio = ($scope.totalHosts - $scope.hostProblems) / $scope.totalHosts * 100; + }); + + $scope.totalServices = sharedData.getData('nbServices', refreshInterval, function (data) { + $scope.totalServices = data; + }); + + $scope.serviceProblems = sharedData.getData('nbServicesOpenProblems', refreshInterval, function (data) { + $scope.serviceProblems = data; + $scope.servicesRatio = ($scope.totalServices - $scope.serviceProblems) / $scope.totalServices * 100; + }); + + // Togglable tabs + // Don't follow hyperlinks + $('a[data-toggle="tab"]').on('click', function (evt) { + evt.preventDefault(); + }); + } + ] + }; + }); diff --git a/app/components/tactical/tactical_test.js b/app/components/directive/tactical/tactical_test.js similarity index 100% rename from app/components/tactical/tactical_test.js rename to app/components/directive/tactical/tactical_test.js diff --git a/app/components/tactical/top_alert_producers/top_alert_producers.html b/app/components/directive/tactical/top_alert_producers/top_alert_producers.html similarity index 100% rename from app/components/tactical/top_alert_producers/top_alert_producers.html rename to app/components/directive/tactical/top_alert_producers/top_alert_producers.html diff --git a/app/components/tactical/top_alert_producers/top_alert_producers.js b/app/components/directive/tactical/top_alert_producers/top_alert_producers.js similarity index 85% rename from app/components/tactical/top_alert_producers/top_alert_producers.js rename to app/components/directive/tactical/top_alert_producers/top_alert_producers.js index b06989c..88ddfb9 100644 --- a/app/components/tactical/top_alert_producers/top_alert_producers.js +++ b/app/components/directive/tactical/top_alert_producers/top_alert_producers.js @@ -21,6 +21,6 @@ angular.module('bansho.tactical.top_alert_producers', ['ngRoute' ]) .directive('banshoTopAlertProducers', function () { return { restrict: 'E', - templateUrl: 'components/tactical/top_alert_producers/top_alert_producers.html' + templateUrl: 'components/directive/tactical/top_alert_producers/top_alert_producers.html' }; }); diff --git a/app/components/tactical/top_alert_producers/top_alert_producers_test.js b/app/components/directive/tactical/top_alert_producers/top_alert_producers_test.js similarity index 100% rename from app/components/tactical/top_alert_producers/top_alert_producers_test.js rename to app/components/directive/tactical/top_alert_producers/top_alert_producers_test.js diff --git a/app/components/directive/title/title.html b/app/components/directive/title/title.html new file mode 100644 index 0000000..bfc838e --- /dev/null +++ b/app/components/directive/title/title.html @@ -0,0 +1,14 @@ +
    +
    +

    {{options.attributes.title}}

    + +

    + There + + + are {{data}} {{item}} + + +

    +
    +
    diff --git a/app/components/directive/title/title.js b/app/components/directive/title/title.js new file mode 100644 index 0000000..c935938 --- /dev/null +++ b/app/components/directive/title/title.js @@ -0,0 +1,22 @@ +'use strict'; + +angular.module('bansho.title', []) + .directive('banshoTitle', ['sharedData', function (sharedData) { + return { + restrict: 'E', + templateUrl: 'components/directive/title/title.html', + scope: { + options: '=' + }, + link: function (scope) { + if (scope.options.attributes.item) { + scope.item = scope.options.attributes.item; + scope.data = sharedData.getData(scope.options.attributes.provider, 30000, function (data) { + scope.data = data; + }); + + scope.isBannerShown = true; + } + } + }; + }]); diff --git a/app/components/host/host.html b/app/components/host/host.html deleted file mode 100644 index 7e0e980..0000000 --- a/app/components/host/host.html +++ /dev/null @@ -1,17 +0,0 @@ -
    -
    - - - - - - - - - - - - - -
    -
    diff --git a/app/components/host/host.js b/app/components/host/host.js deleted file mode 100644 index 0147c4b..0000000 --- a/app/components/host/host.js +++ /dev/null @@ -1,68 +0,0 @@ -'use strict'; - -angular.module('bansho.host', ['bansho.surveil', - 'bansho.host.main', - 'bansho.host.live', - 'bansho.host.load', - 'bansho.host.cpu', - 'bansho.host.info', - 'bansho.host.services_list']) - - .value('hostConfig', {}) - - .controller('HostCtrl', ['$scope', 'hostConfig', 'surveilStatus', function ($scope, hostConfig, surveilStatus) { - var objectType = 'host', - objectIdentifier = {}; - - objectIdentifier.host_name = hostConfig.hostName; - surveilStatus.getHost(objectType, objectIdentifier).then(function (data) { - $scope.host = data; - $scope.data = data; - - surveilStatus.getServicesByHost($scope.hostName).success(function (data) { - var i, - service; - - $scope.host.services = data; - - for (i = 0; i < $scope.host.services.length;) { - service = $scope.host.services[i]; - if (service.service_description === "cpu") { - $scope.host.cpuService = service; - $scope.host.services.splice(i, 1); - } else if (service.service_description === "load") { - $scope.host.loadService = service; - $scope.host.services.splice(i, 1); - } else { - ++i; - } - } - }); - }); - }]) - - .directive('banshoHost', ['$http', '$compile', 'surveilStatus', 'hostConfig', - function ($http, $compile, surveilStatus, hostConfig) { - return { - restrict: 'E', - compile: function () { - return function (scope, element, attrs) { - - var template = 'components/host/host.html'; - - if (!attrs.hostName) { - throw new Error(' "host-name" attribute must be defined'); - } - - hostConfig.hostName = {}; - hostConfig.hostName = attrs.hostName; - - $http.get(template, { cache: true }) - .success(function (data) { - var elem = $compile(data)(scope); - element.append(elem); - }); - }; - } - }; - }]); diff --git a/app/components/host/host_cpu/host_cpu.html b/app/components/host/host_cpu/host_cpu.html deleted file mode 100644 index 25db828..0000000 --- a/app/components/host/host_cpu/host_cpu.html +++ /dev/null @@ -1,15 +0,0 @@ -
    -

    Cpu

    - - - - - - - - - - - -
    State {{host.cpuService.state}}
    Output{{host.cpuService.plugin_output}}
    -
    diff --git a/app/components/host/host_cpu/host_cpu.js b/app/components/host/host_cpu/host_cpu.js deleted file mode 100644 index a530ed2..0000000 --- a/app/components/host/host_cpu/host_cpu.js +++ /dev/null @@ -1,12 +0,0 @@ -'use strict'; - -angular.module('bansho.host.cpu', ['bansho.surveil']) - .directive('banshoHostCpu', function () { - return { - restrict: 'E', - compile: function (scope, element, attrs) { - scope.host = attrs.host; - }, - templateUrl: 'components/host/host_cpu/host_cpu.html' - }; - }); diff --git a/app/components/host/host_info/host_info.html b/app/components/host/host_info/host_info.html deleted file mode 100644 index fce0006..0000000 --- a/app/components/host/host_info/host_info.html +++ /dev/null @@ -1,35 +0,0 @@ -
    -

    Info

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Last check{{data.live.last_check | timeElapsed}}
    Check period{{data.config.check_period}}
    Notification period{{data.config.notification_period}}
    Active checks{{active_checks}}
    Notifications{{notifications_enabled}}
    Event Handler{{event_handler_enabled}}
    Flag detection{{flap_detection_enabled}}
    -
    diff --git a/app/components/host/host_info/host_info.js b/app/components/host/host_info/host_info.js deleted file mode 100644 index 399357e..0000000 --- a/app/components/host/host_info/host_info.js +++ /dev/null @@ -1,17 +0,0 @@ -'use strict'; - -angular.module('bansho.host.info', []) - - .controller('HostInfoCtrl', ['$scope', function ($scope) { - $scope.active_checks = ($scope.data.live.active_checks_enabled === '1') ? 'Enabled' : 'Disabled'; - $scope.notifications_enabled = ($scope.data.config.notifications_enabled === '1') ? 'Enabled' : 'Disabled'; - $scope.event_handler_enabled = ($scope.data.config.event_handler_enabled === '1') ? 'Enabled' : 'Disabled'; - $scope.flap_detection_enabled = ($scope.data.config.flap_detection_enabled === '1') ? 'Enabled' : 'Disabled'; - }]) - - .directive('banshoHostInfo', function () { - return { - restrict: 'E', - templateUrl: 'components/host/host_info/host_info.html' - }; - }); diff --git a/app/components/host/host_live/host_live.html b/app/components/host/host_live/host_live.html deleted file mode 100644 index b2b9a2f..0000000 --- a/app/components/host/host_live/host_live.html +++ /dev/null @@ -1,15 +0,0 @@ -
    -

    Status

    - - - - - - - - - - - -
    State {{host.live.state}}
    Output{{host.live.plugin_output}}
    -
    diff --git a/app/components/host/host_live/host_live.js b/app/components/host/host_live/host_live.js deleted file mode 100644 index b03ac31..0000000 --- a/app/components/host/host_live/host_live.js +++ /dev/null @@ -1,17 +0,0 @@ -'use strict'; - -angular.module('bansho.host.live', []) - - .controller('HostLiveCtrl', ['$scope', function ($scope) { - angular.noop(); - }]) - - .directive('banshoHostLive', function () { - return { - restrict: 'E', - compile: function (scope, element, attrs) { - scope.host = attrs.host; - }, - templateUrl: 'components/host/host_live/host_live.html' - }; - }); diff --git a/app/components/host/host_load/host_load.html b/app/components/host/host_load/host_load.html deleted file mode 100644 index 467a143..0000000 --- a/app/components/host/host_load/host_load.html +++ /dev/null @@ -1,16 +0,0 @@ -
    -

    Load

    - - - - - - - - - - - - -
    State {{host.loadService.state}}
    Output{{host.loadService.plugin_output}}
    -
    diff --git a/app/components/host/host_load/host_load.js b/app/components/host/host_load/host_load.js deleted file mode 100644 index f7d2f29..0000000 --- a/app/components/host/host_load/host_load.js +++ /dev/null @@ -1,12 +0,0 @@ -'use strict'; - -angular.module('bansho.host.load', []) - .directive('banshoHostLoad', ['iframeUrl', function (iframeUrl) { - return { - restrict: 'E', - controller: ['$scope', function ($scope, element, attrs) { - $scope.iframeUrl = iframeUrl.getIFrameUrl("metric_load1", $scope.host.config.host_name, "load"); - }], - templateUrl: 'components/host/host_load/host_load.html' - }; - }]); diff --git a/app/components/host/host_main/host_main.html b/app/components/host/host_main/host_main.html deleted file mode 100644 index 48ce4b1..0000000 --- a/app/components/host/host_main/host_main.html +++ /dev/null @@ -1,7 +0,0 @@ -
    -

    - {{host.config.host_name}} - (host.config.alias) - {{host.config.address}} -

    -
    diff --git a/app/components/host/host_main/host_main.js b/app/components/host/host_main/host_main.js deleted file mode 100644 index 0a8d514..0000000 --- a/app/components/host/host_main/host_main.js +++ /dev/null @@ -1,17 +0,0 @@ -'use strict'; - -angular.module('bansho.host.main', []) - - .controller('HostMainCtrl', ['$scope', function ($scope) { - angular.noop(); - }]) - - .directive('banshoHostMain', function () { - return { - restrict: 'E', - compile: function (scope, element, attrs) { - scope.host = attrs.host; - }, - templateUrl: 'components/host/host_main/host_main.html' - }; - }); diff --git a/app/components/host/host_services_list/host_services_list.html b/app/components/host/host_services_list/host_services_list.html deleted file mode 100644 index cfcf531..0000000 --- a/app/components/host/host_services_list/host_services_list.html +++ /dev/null @@ -1,19 +0,0 @@ -
    -

    Services

    - - - - - - - - - - - - - - -
    Service descriptionAcknowledgedState
    {{service.service_description}} - {{service.acknowledged}}{{service.state}}
    -
    diff --git a/app/components/host/host_services_list/host_services_list.js b/app/components/host/host_services_list/host_services_list.js deleted file mode 100644 index aba26f6..0000000 --- a/app/components/host/host_services_list/host_services_list.js +++ /dev/null @@ -1,12 +0,0 @@ -'use strict'; - -angular.module('bansho.host.services_list', []) - .directive('banshoHostServicesList', function () { - return { - restrict: 'E', - compile: function (scope, element, attrs) { - scope.host = attrs.host; - }, - templateUrl: 'components/host/host_services_list/host_services_list.html' - }; - }); diff --git a/app/components/service/service.html b/app/components/service/service.html deleted file mode 100644 index cfa6191..0000000 --- a/app/components/service/service.html +++ /dev/null @@ -1,13 +0,0 @@ -
    -
    - - - - - - - - - -
    -
    diff --git a/app/components/service/service.js b/app/components/service/service.js deleted file mode 100644 index e67b4e3..0000000 --- a/app/components/service/service.js +++ /dev/null @@ -1,50 +0,0 @@ -'use strict'; - -angular.module('bansho.service', ['bansho.surveil', - 'bansho.service.main', - 'bansho.service.live', - 'bansho.service.info', - 'bansho.service.metrics', - 'bansho.service.graphs', - 'bansho.table.state_icon']) - - .value('serviceConfig', {}) - - .controller('ServiceCtrl', ['$scope', 'serviceConfig', 'surveilStatus', - function ($scope, serviceConfig, surveilStatus) { - var hostName = serviceConfig.hostName, - description = serviceConfig.description; - - surveilStatus.getService(hostName, description).success(function (data) { - $scope.service = data[0]; - }); - }]) - - .directive('banshoService', ['$http', '$compile', 'serviceConfig', - function ($http, $compile, serviceConfig) { - return { - restrict: 'E', - compile: function () { - return function (scope, element, attrs) { - - var template = 'components/service/service.html'; - - if (!attrs.hostName && !!attrs.description) { - throw new Error(' "host-name" and "description" attributes must be defined'); - } - - serviceConfig.hostName = ''; - serviceConfig.hostName = attrs.hostName; - - serviceConfig.description = ''; - serviceConfig.description = attrs.description; - - $http.get(template, { cache: true }) - .success(function (data) { - var elem = $compile(data)(scope); - element.append(elem); - }); - }; - } - }; - }]); diff --git a/app/components/service/service_graphs/service_graphs.js b/app/components/service/service_graphs/service_graphs.js deleted file mode 100644 index 7f35be1..0000000 --- a/app/components/service/service_graphs/service_graphs.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict'; - -angular.module('bansho.service.graphs', []) - - .controller('ServiceGraphsCtrl', ['$scope', 'surveilStatus', 'iframeUrl', function ($scope, surveilStatus, iframeUrl) { - $scope.$watch('service', function(service) { - if (service) { - surveilStatus.getServiceMetricNames(service.host_name, service.service_description).then(function(metric_names){ - $scope.iframeUrls = {}; - angular.forEach(metric_names, function (metric) { - var metricName = metric.metric_name.substr(7); - $scope.iframeUrls[metricName] = iframeUrl.getIFrameUrl(metric.metric_name, service.host_name, service.service_description); - }); - }); - } - }); - }]) - - .directive('banshoServiceGraphs', ['iframeUrl', function (iframeUrl) { - return { - restrict: 'E', - scope: { - service: '=service' - }, - controller: 'ServiceGraphsCtrl', - templateUrl: 'components/service/service_graphs/service_graphs.html' - }; - }]); diff --git a/app/components/service/service_info/service_info.js b/app/components/service/service_info/service_info.js deleted file mode 100644 index 8c7be4c..0000000 --- a/app/components/service/service_info/service_info.js +++ /dev/null @@ -1,17 +0,0 @@ -'use strict'; - -angular.module('bansho.service.info', []) - - .controller('ServiceInfoCtrl', ['$scope', function ($scope) { - $scope.isAcknowledged = $scope.acknowledged === "1" ? "Yes" : "No"; - }]) - - .directive('banshoServiceInfo', function () { - return { - restrict: 'E', - scope: { - service: '=service' - }, - templateUrl: 'components/service/service_info/service_info.html' - }; - }); diff --git a/app/components/service/service_live/service_live.html b/app/components/service/service_live/service_live.html deleted file mode 100644 index d43c9f9..0000000 --- a/app/components/service/service_live/service_live.html +++ /dev/null @@ -1,15 +0,0 @@ -
    -

    Status

    - - - - - - - - - - - -
    State {{service.state}}
    Output{{service.plugin_output}}
    -
    diff --git a/app/components/service/service_live/service_live.js b/app/components/service/service_live/service_live.js deleted file mode 100644 index 7486ca9..0000000 --- a/app/components/service/service_live/service_live.js +++ /dev/null @@ -1,19 +0,0 @@ -'use strict'; - -angular.module('bansho.service.live', []) - - .controller('ServiceLiveCtrl', ['$scope', function ($scope) { - angular.noop(); - }]) - - .directive('banshoServiceLive', function () { - return { - restrict: 'E', - scope: { - service: '=service' - }, - templateUrl: 'components/service/service_live/service_live.html', - controller: 'ServiceLiveCtrl' - - }; - }); diff --git a/app/components/service/service_main/service_main.html b/app/components/service/service_main/service_main.html deleted file mode 100644 index a1f06b3..0000000 --- a/app/components/service/service_main/service_main.html +++ /dev/null @@ -1,7 +0,0 @@ -
    -

    {{service.service_description}} - - {{service.host_name}} - -

    -
    diff --git a/app/components/service/service_main/service_main.js b/app/components/service/service_main/service_main.js deleted file mode 100644 index 5548a3c..0000000 --- a/app/components/service/service_main/service_main.js +++ /dev/null @@ -1,19 +0,0 @@ -'use strict'; - -angular.module('bansho.service.main', []) - - .controller('ServiceMainCtrl', ['$scope', function ($scope) { - angular.noop(); - }]) - - .directive('banshoServiceMain', function () { - return { - restrict: 'E', - scope: { - service: '=service' - }, - templateUrl: 'components/service/service_main/service_main.html', - controller: 'ServiceMainCtrl' - - }; - }); diff --git a/app/components/service/service_metrics/service_metrics.html b/app/components/service/service_metrics/service_metrics.html deleted file mode 100644 index 796819c..0000000 --- a/app/components/service/service_metrics/service_metrics.html +++ /dev/null @@ -1,3 +0,0 @@ -
    -

    Metrics

    -
    diff --git a/app/components/surveil/query.js b/app/components/surveil/query.js new file mode 100644 index 0000000..b9ed4e7 --- /dev/null +++ b/app/components/surveil/query.js @@ -0,0 +1,18 @@ +'use strict'; + +angular.module('bansho.surveil') + .factory('surveilQuery', [ + function() { + return function (fields, filters, paging, timeInterval) { + var query = {}; + + if (fields.length > 0) { + query.fields = JSON.stringify(fields); + } + query.filters = JSON.stringify(filters); + + // TODO handle paging and timeInterval + + return query; + }; + }]); diff --git a/app/components/surveil/status.js b/app/components/surveil/status.js index 7bbad32..9418d07 100644 --- a/app/components/surveil/status.js +++ b/app/components/surveil/status.js @@ -3,47 +3,8 @@ 'use strict'; angular.module('bansho.surveil') - .service('surveilStatus', ['$http', '$q', - function ($http, $q) { - var getObjects = function (fields, filters, apiName) { - var query = {}, - transformations; - - function appendTransform(defaults, transform) { - // We can't guarantee that the default transformation is an array - defaults = angular.isArray(defaults) ? defaults : [defaults]; - - return defaults.concat(transform); - } - - if (apiName === 'hosts') { - transformations = hostMiddleware; - } else if (apiName === 'services' || apiName === 'events') { - transformations = apiMiddleware; - } else { - throw new Error('getObjects : ' + apiName + ' API is not supported'); - } - - if (apiName === 'hosts') { - hostQueryTransform(fields, filters); - } - - if (fields.length > 0) { - query.fields = fields; - } - - query.filters = JSON.stringify(filters); - - return $http({ - url: 'surveil/v2/status/' + apiName + '/', - method: 'POST', - data: query, - transformResponse: appendTransform($http.defaults.transformResponse, transformations), - }).error(function () { - throw new Error('getObjects : POST Request failed'); - }); - }; - + .service('surveilStatus', ['$http', '$q', 'surveilQuery', 'componentsConfig', + function ($http, $q, surveilQuery, componentsConfig) { var getMetric = function (host, service, metric) { var url = 'surveil/v2/status/hosts/' + host, responsePromise = $q.defer(); @@ -56,8 +17,7 @@ angular.module('bansho.surveil') $http.get(url).success(function (metric) { responsePromise.resolve(metric); - }) - .error(function () { + }).error(function () { throw new Error('getMetric: GET Request failed'); }); @@ -77,360 +37,216 @@ angular.module('bansho.surveil') $http.get(url).success(function (metrics) { var result = []; for (var i = 0; i < metrics.length; i += 1) { - if (metrics[i].metric_name.indexOf("metric_") === 0) { + if (metrics[i].metric_name.indexOf("metric_") === 0) { result.push(metrics[i]); } } responsePromise.resolve(result); - }) - .error(function () { - throw new Error('getMetricNames: GET Request failed'); + }).error(function () { + throw new Error('getMetricNames: GET Request failed'); }); return responsePromise.promise; }; - var getService = function (hostName, description) { - var fields = [], - filters = { - 'is': { - 'host_name': [hostName], - 'service_description': [description] - } - }; - - return this.getObjects(fields, filters, 'services') - .error(function () { - throw new Error('getService : POST Request failed'); - }); + var executeQuery = function (url, method, query) { + return $http({ + url: url, + method: method, + data: query + }).error(function () { + throw new Error('executeQuery : ' + method + ' Request failed'); + }); }; - var getServicesByHost = function (hostName) { - var fields = [], - filters = { - 'is': { - 'host_name': [hostName] - } - }; + var getData = function (fields, filters, endpoint) { + var promise = $q.defer(); - return this.getObjects(fields, filters, 'services') - .error(function () { - throw new Error('getService : POST Request failed'); - }); + if (!queryEndpoint[endpoint]) { + throw new Error('getData in surveilStatus : Invalid endpoint ' + endpoint); + } + + queryEndpoint[endpoint](fields, filters, function (data) { + promise.resolve(data); + }); + + return promise.promise; }; - var getHostOpenProblems = function () { - var fields = ['state'], - filters = { - 'is': { - 'state': ['DOWN', 'UNREACHABLE'], - 'acknowledged': [false] - } - }, - apiName = 'hosts'; + var queryHostsServices = function (fields, filters, callback) { + var hostQuery = surveilQuery(fields, filters.hosts), + serviceQuery = surveilQuery(fields, filters.services); - return getObjects(fields, filters, apiName) - .error(function () { - throw new Error('getHostOpenProblems : POST Request failed'); - }); - }; - - var getServiceOpenProblems = function () { - var serviceFields = ['host_name', 'state'], - serviceFilters = { - 'isnot': { - 'state': ['OK'] - }, - 'is': { - 'acknowledged': [false] - } - }, - hostFields = ['host_name', 'state'], - hostFilters = {'isnot': {'state': ['DOWN', 'UNREACHABLE']}}, - responsePromise = $q.defer(); - - getObjects(hostFields, hostFilters, 'hosts') - .success(function (hostData) { - var hostsResult = {}, - i; - - // Creates a host dictionnary for performance - for (i = 0; i < hostData.length; i += 1) { - hostsResult[hostData[i].host_name] = ''; - } - - getObjects(serviceFields, serviceFilters, 'services') - .success(function (serviceData) { - var result = []; - for (i = 0; i < serviceData.length; i += 1) { - if (serviceData[i].host_name in hostsResult) { - result.push(serviceData[i]); - } - } - responsePromise.resolve(result); + executeQuery('surveil/v2/status/hosts/', 'POST', hostQuery) + .success(function (hosts) { + executeQuery('surveil/v2/status/services/', 'POST', serviceQuery) + .success(function (services) { + callback(hosts, services); }); }); - - return responsePromise.promise; }; - var getHostProblems = function () { - var fields = ['state'], - filters = {'isnot': {'state': ['UP']}}, - apiName = 'hosts'; + var createHostsDict = function (hosts) { + var hostsDict = {}; + if (!(hosts instanceof Array)) { + hosts = [hosts]; + } - return getObjects(fields, filters, apiName) - .error(function () { - throw new Error('getHostProblems : POST Request failed'); + angular.forEach(hosts, function (host) { + var hostDict = {}; + angular.forEach(host, function (value, attr) { + hostDict['host_' + attr] = value; }); - }; - // This service is used to count the number of service problems - var getServiceProblems = function () { - var fields = ['state'], - filters = {'isnot': {'state': ['OK']}}, - apiName = 'services'; - - return getObjects(fields, filters, apiName) - .error(function () { - throw new Error('getServiceOpenProblems : POST Request failed'); - }); - }; - - // This service is used to count the number of hosts - var getTotalHosts = function () { - var fields = ['host_name'], - filters = {}, - apiName = 'hosts'; - - return getObjects(fields, filters, apiName) - .error(function () { - throw new Error('getTotalHosts : POST Request failed'); - }); - }; - - // This service is used to count the number of services - var getTotalServices = function () { - var fields = ['host_name'], - filters = {}, - apiName = 'services'; - - return getObjects(fields, filters, apiName) - .error(function () { - throw new Error('getTotalServices : POST Request failed'); - }); - }; - - var getHost = function (objectType, objectIdentifier) { - var objectData = {}, - endpoints = { - "host": "hosts", - "service": "services" - }, - liveUrl = 'surveil/v2/status/' + endpoints[objectType] + '/' + objectIdentifier.host_name + '/', - configUrl = 'surveil/v2/config/' + endpoints[objectType] + '/' + objectIdentifier.host_name + '/', - responsePromise = $q.defer(); - - $http.get(liveUrl).success(function (liveData) { - $http.get(configUrl).success(function (configData) { - objectData.live = liveData; - objectData.config = configData; - responsePromise.resolve(objectData); - }); + hostsDict[host.host_name] = hostDict; }); - return responsePromise.promise; + return hostsDict; }; - var getHostMetric = function (host, metric) { - return getMetric(host, undefined, metric); - }; + var queryEndpoint = { + "services": function (fields, filters, callback) { + queryHostsServices(fields, filters, function (hosts, services) { + var hostsDict = createHostsDict(hosts), + response = []; - var getHostMetricNames = function (host, metric) { - return getMetricNames(host, undefined); - }; + angular.forEach(services, function (service) { + var serviceDict = {}; + angular.forEach(service, function (value, attr) { + serviceDict['service_' + attr] = value; + }); - var getServiceMetric = function (host, service, metric) { - return getMetric(host, service, metric); - }; - - var getServiceMetricNames = function (host, service) { - return getMetricNames(host, service); - }; - - var hostQueryTransform = function (fields, filters) { - var i, - transformations = { - 'host_state': 'state', - }; - - for (i = 0; i < fields.length; i += 1) { - if (fields[i] in transformations) { - fields[i] = transformations[fields[i]]; - } - } - }; - - // Modify response object to conform to web ui - var hostMiddleware = function (data) { - var i = 0, - conversions = { - 'state': 'host_state' - }; - - for (i = 0; i < data.length; i += 1) { - angular.forEach(data[i], function (value, field) { - if (field in conversions) { - data[i][conversions[field]] = value; - delete data[i][field]; - } - }); - } - - return data; - }; - - // Modify response object to conform to web ui - var apiMiddleware = function (data) { - var i = 0, - conversions = {}; - - if (jQuery.isEmptyObject(conversions)) { - return data; - } - - for (i = 0; i < data.length; i += 1) { - angular.forEach(data[i], function (value, field) { - if (field in conversions) { - data[i][conversions[field]] = value; - delete data[i][field]; - } - }); - } - - return data; - }; - - var getTableData = function (fields, inputSourceConfig) { - var hostFields = [], - serviceFields = [], - hostFilters = {}, - serviceFilters = {}, - hostKeys = { - 'host_state': 'state', - 'address': 'address', - 'childs': 'childs' - }, - responsePromise = $q.defer(), - i, - found = false; - - if (inputSourceConfig.apiName === 'hosts') { - this.getObjects(fields, inputSourceConfig.filters, 'hosts') - .success(function (data) { - responsePromise.resolve(data); - }); - return responsePromise.promise; - } else if (inputSourceConfig.apiName === 'services') { - angular.forEach(fields, function (field) { - if (field in hostKeys) { - hostFields.push(hostKeys[field]); - } else { - serviceFields.push(field); - } - }); - - // Make sure that 'host_name' is in both queries as we - // use this field to merge data - if ($.inArray('host_name', hostFields) === -1) { - hostFields.push('host_name'); - } - if ($.inArray('host_name', serviceFields) === -1) { - serviceFields.push('host_name'); - } - - angular.forEach(inputSourceConfig.filters, function (filterData, filterName) { - angular.forEach(filterData, function (values, field) { - if (field in hostKeys) { - if (!(filterData in hostFilters)) { - hostFilters[filterName] = {}; - } - hostFilters[filterName][hostKeys[field]] = values; - } else { - if (!(filterData in serviceFilters)) { - serviceFilters[filterName] = {}; - } - serviceFilters[filterName][field] = values; + if (hostsDict[serviceDict.service_host_name]) { + angular.extend(serviceDict, hostsDict[serviceDict.service_host_name]); + response.push(serviceDict); } }); + + callback(response); }); + }, + "hosts": function (fields, filters, callback) { + var hostQuery = surveilQuery(fields, filters.hosts), + method = 'POST', + hostUrl = 'surveil/v2/status/hosts/'; - // Queries host and service APIs and merges responses - getObjects(hostFields, hostFilters, 'hosts') - .success(function (hostData) { - getObjects(serviceFields, serviceFilters, 'services') - .success(function (serviceData) { - var hostDict = {}; + if (filters.hosts && filters.hosts.is && filters.hosts.is.host_name) { + hostUrl += filters.hosts.is.host_name; + method = 'GET'; + } - // Create a host dict for performance - for (i = 0; i < hostData.length; i += 1) { - var host_name = hostData[i].host_name; + executeQuery(hostUrl, method, hostQuery) + .success(function (hosts) { + var hostsDict = createHostsDict(hosts), + response = []; - angular.forEach(hostData[i], function (value, field) { - if (!(host_name in hostDict)) { - hostDict[host_name] = {}; - } + angular.forEach(hostsDict, function (host) { + response.push(host); + }); - hostDict[host_name][field] = value; - }); - } + callback(response); + }); + }, + "events": function (fields, filters, callback) { + var query = surveilQuery(fields, filters.events); - for (i = 0; i < serviceData.length; i += 1) { - angular.forEach(hostDict[serviceData[i].host_name], - function (value, field) { - serviceData[i][field] = value; - }); - } - - responsePromise.resolve(serviceData); + executeQuery('surveil/v2/status/events/', 'POST', query) + .success(function (events) { + angular.forEach(events, function (event) { + angular.forEach(event, function (value, attr) { + event['event_' + attr] = event[attr]; + delete event[attr]; }); + }); + + callback(events); }); - - return responsePromise.promise; - } else if (inputSourceConfig.apiName === 'events') { - var queryFields = []; - - // Queries events API - if (inputSourceConfig.fields) - queryFields = inputSourceConfig.fields; - - getObjects(queryFields, inputSourceConfig.filters, 'events') - .success(function (eventsData) { - responsePromise.resolve(eventsData); - }); - - return responsePromise.promise; } }; return { - getHost: getHost, - getObjects : getObjects, - getService : getService, - hostQueryTransform: hostQueryTransform, - getHostOpenProblems: getHostOpenProblems, - hostMiddleware: hostMiddleware, - getServiceProblems: getServiceProblems, - getServiceOpenProblems: getServiceOpenProblems, - getHostProblems: getHostProblems, - getTableData: getTableData, - getTotalHosts: getTotalHosts, - getTotalServices: getTotalServices, - getServicesByHost: getServicesByHost, - getHostMetric: getHostMetric, - getHostMetricNames: getHostMetricNames, - getServiceMetric: getServiceMetric, - getServiceMetricNames: getServiceMetricNames + getData: getData, + getHost: function (hostname) { + var promise = $q.defer(), query = {"hosts": {"is": {"host_name": [ hostname ] } } }; + getData([], query, "hosts") + .then(function (data) { + promise.resolve(data); + }); + return promise.promise; + }, + getNbHosts: function () { + var promise = $q.defer(); + getData([], componentsConfig.getFilter("all").filter, "hosts") + .then(function (data) { + promise.resolve(data.length); + }); + return promise.promise; + }, + getNbHostOpenProblems: function () { + var promise = $q.defer(); + getData([], componentsConfig.getFilter("allHostOpenProblems").filter, "hosts") + .then(function (data) { + promise.resolve(data.length); + }); + return promise.promise; + }, + getNbHostsProblems: function () { + var promise = $q.defer(); + getData([], componentsConfig.getFilter("allHostsProblems").filter, "hosts") + .then(function (data) { + promise.resolve(data.length); + }); + return promise.promise; + }, + getService: function (hostname, serviceDescription) { + var promise = $q.defer(), query = { "hosts": { "is": { "host_name": [hostname] } }, "services": {"is": {"host_name": [hostname] } } }; + + if (serviceDescription) { + query.services = { "is": { "service_description": [ serviceDescription ] } }; + } + + getData([], query, "services") + .then(function (data) { + promise.resolve(data); + }); + return promise.promise; + }, + getNbServices: function () { + var promise = $q.defer(); + getData([], componentsConfig.getFilter("allServices").filter, "services") + .then(function (data) { + promise.resolve(data.length); + }); + return promise.promise; + }, + getNbServiceOpenProblems: function () { + var promise = $q.defer(); + getData([], componentsConfig.getFilter("allServiceOpenProblems").filter, "services") + .then(function (data) { + promise.resolve(data.length); + }); + return promise.promise; + }, + getNbServiceOpenProblemsOnly: function () { + var promise = $q.defer(); + getData([], componentsConfig.getFilter("allServiceOpenProblemsOnly").filter, "services") + .then(function (data) { + promise.resolve(data.length); + }); + return promise.promise; + }, + getHostMetric: function (host, metric) { + return getMetric(host, undefined, metric); + }, + getHostMetricNames: function (host) { + return getMetricNames(host, undefined); + }, + getServiceMetric: function (host, service, metric) { + return getMetric(host, service, metric); + }, + getServiceMetricNames: function (host, service) { + return getMetricNames(host, service); + } }; }]); diff --git a/app/components/table/actionbar/actionbar.js b/app/components/table/actionbar/actionbar.js deleted file mode 100644 index 85268aa..0000000 --- a/app/components/table/actionbar/actionbar.js +++ /dev/null @@ -1,25 +0,0 @@ -'use strict'; - -angular.module('bansho.table.actionbar', ['bansho.table', 'bansho.surveil', 'bansho.notifications']) - .directive('banshoActionbar', ['$compile', function ($compile) { - return { - restrict: 'E', - scope: { - tableId: '=' - }, - templateUrl: 'components/table/actionbar/actionbar.html', - compile: function () { - return function (scope, element, attrs) { - scope.components = attrs.components.split(','); - if (angular.isArray(scope.components)) { - angular.forEach(scope.components, function (component) { - var banshoDirective = ""; - - element.append(banshoDirective); - $compile(element.contents())(scope); - }); - } - }; - } - }; - }]); diff --git a/app/components/table/actionbar/actions/actions.js b/app/components/table/actionbar/actions/actions.js deleted file mode 100644 index 1d72edf..0000000 --- a/app/components/table/actionbar/actions/actions.js +++ /dev/null @@ -1,111 +0,0 @@ -'use strict'; - -angular.module('bansho.table.actionbar') - - .directive('banshoAcknowledgeForm', function () { - return { - restrict: 'E', - templateUrl: 'components/table/actionbar/actions/acknowledge_form.html', - scope: { - tableId: '=', - isShown: '=' - }, - controller: ['$scope', 'tables', 'surveilActions', 'notifications', - function ($scope, tables, surveilActions, notifications) { - $scope.acknowledgeProblems = function () { - angular.forEach($scope.tableId, function (tableId) { - tables.forEachCheckedEntry(tableId, function (entry) { - var service_description; - - if ('description' in entry) { - service_description = entry.description; - } - - surveilActions.acknowledge(entry.host_name, service_description, $scope.attrs).then(function (data) { - notifications.push('success', 'Acknowledgement', 'Acknowledged ' + entry.host_name); - }, - function (error) { - notifications.push('error', 'Acknowledgement', 'Could not acknowledge ' + entry.host_name); - }); - }); - - tables.setAllCheckTable(tableId, false); - }); - - $scope.isShown = false; - }; - } - ] - }; - }) - - .directive('banshoDowntimeForm', function () { - return { - restrict: 'E', - templateUrl: 'components/table/actionbar/actions/downtime_form.html', - scope: { - tableId: '=', - isShown: '=' - }, - controller: ['$scope', 'tables', 'surveilActions', 'notifications', - function ($scope, tables, surveilActions, notifications) { - $scope.sendDowntime = function () { - angular.forEach($scope.tableId, function (tableId) { - tables.forEachCheckedEntry(tableId, function (entry) { - var service_description; - - if ('description' in entry) { - service_description = entry.description; - } - - surveilActions.downtime(entry.host_name, service_description, $scope.attrs).then(function (data) { - notifications.push('success', 'Downtime', 'Added downtime for ' + entry.host_name); - }, - function (error) { - notifications.push('error', 'Downtime', 'Could not add downtime for ' + entry.host_name); - }); - }); - - tables.setAllCheckTable(tableId, false); - }); - - $scope.isShown = false; - }; - } - ] - }; - }) - - .directive('banshoRecheckButton', function () { - return { - restrict: 'E', - templateUrl: 'components/table/actionbar/actions/recheck_button.html', - scope: { - tableId: '=' - }, - controller: ['$scope', 'tables', 'surveilActions', 'notifications', - function ($scope, tables, surveilActions, notifications) { - $scope.sendRecheck = function () { - angular.forEach($scope.tableId, function (tableId) { - tables.forEachCheckedEntry(tableId, function (entry) { - var service_description; - - if ('description' in entry) { - service_description = entry.description; - } - - surveilActions.recheck(entry.host_name, service_description).then(function (data) { - notifications.push('success', 'Recheck', 'Scheduled recheck for ' + entry.host_name); - }, - function (error) { - notifications.push('error', 'Recheck', 'Could not schedule recheck for ' + entry.host_name); - }); - }); - - tables.setAllCheckTable(tableId, false); - }); - }; - } - ] - }; - }); diff --git a/app/components/table/actionbar/component_downtime/downtime.js b/app/components/table/actionbar/component_downtime/downtime.js deleted file mode 100644 index 9cedc24..0000000 --- a/app/components/table/actionbar/component_downtime/downtime.js +++ /dev/null @@ -1,43 +0,0 @@ -'use strict'; - -angular.module('bansho.table.actionbar') - .directive('banshoActionbarDowntime', [function () { - return { - restrict: 'E', - templateUrl: 'components/table/actionbar/component_downtime/downtime.html', - scope: { - tableId: '=' - }, - controller: ['$scope', 'tables', 'surveilActions', 'notifications', - function ($scope, tables, surveilActions, notifications) { - $scope.isDowntimeFormShown = false; - $scope.switchDowntimeFormShown = function () { - $scope.isDowntimeFormShown = !$scope.isDowntimeFormShown; - }; - - $scope.sendDowntime = function () { - angular.forEach($scope.tableId, function (tableId) { - tables.forEachCheckedEntry(tableId, function (entry) { - var service_description; - - if ('description' in entry) { - service_description = entry.description; - } - - surveilActions.downtime(entry.host_name, service_description, $scope.attrs).then(function (data) { - notifications.push('success', 'Downtime', 'Added downtime for ' + entry.host_name); - }, - function (error) { - notifications.push('error', 'Downtime', 'Could not add downtime for ' + entry.host_name); - }); - }); - - tables.setAllCheckTable(tableId, false); - }); - - $scope.isDowntimeFormShown = false; - }; - } - ] - }; - }]); diff --git a/app/components/table/actionbar/component_filter/filter.js b/app/components/table/actionbar/component_filter/filter.js deleted file mode 100644 index b91428d..0000000 --- a/app/components/table/actionbar/component_filter/filter.js +++ /dev/null @@ -1,39 +0,0 @@ -'use strict'; - -angular.module('bansho.table.actionbar') - .directive('banshoActionbarFilter', [function () { - return { - restrict: 'EA', - scope: { - 'tableId': '=' - }, - templateUrl: 'components/table/actionbar/component_filter/filter.html', - controller: ['$scope', 'tables', function ($scope, tables) { - $scope.possibleFilters = [ - { - text: "All", - name: "all" - }, - { - text: "All OK", - name: "all_ok" - }, - { - text: "All Acknowledged", - name: "all_acknowledged" - }, - { - text: "All in Downtime", - name: "all_downtime" - }]; - - $scope.activeFilter = $scope.possibleFilters[0]; - $scope.activateFilter = function (item) { - $scope.activeFilter = $scope.possibleFilters[item]; - angular.forEach($scope.tableId, function (tableId) { - console.log("not yet implemented"); - }); - }; - }] - }; - }]); diff --git a/app/components/table/actionbar/component_more/more.js b/app/components/table/actionbar/component_more/more.js deleted file mode 100644 index 199adf3..0000000 --- a/app/components/table/actionbar/component_more/more.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict'; - -angular.module('bansho.table.actionbar') - .directive('banshoActionbarMore', [function () { - return { - restrict: 'E', - scope: { - 'tableId': '=' - }, - templateUrl: 'components/table/actionbar/component_more/more.html', - controller: ['$scope', 'tables', function ($scope, tables) {}] - }; - }]); diff --git a/app/components/table/actionbar/component_recheck/recheck.js b/app/components/table/actionbar/component_recheck/recheck.js deleted file mode 100644 index 795f82e..0000000 --- a/app/components/table/actionbar/component_recheck/recheck.js +++ /dev/null @@ -1,36 +0,0 @@ -'use strict'; - -angular.module('bansho.table.actionbar') - .directive('banshoActionbarRecheck', [function () { - return { - restrict: 'EA', - scope: { - 'tableId': '=' - }, - templateUrl: 'components/table/actionbar/component_recheck/recheck.html', - controller: ['$scope', 'tables', 'surveilActions', 'notifications', - function ($scope, tables, surveilActions, notifications) { - $scope.sendRecheck = function () { - angular.forEach($scope.tableId, function (tableId) { - tables.forEachCheckedEntry(tableId, function (entry) { - var service_description; - - if ('description' in entry) { - service_description = entry.description; - } - - surveilActions.recheck(entry.host_name, service_description).then(function (data) { - notifications.push('success', 'Recheck', 'Scheduled recheck for ' + entry.host_name); - }, - function (error) { - notifications.push('error', 'Recheck', 'Could not schedule recheck for ' + entry.host_name); - }); - }); - - tables.setAllCheckTable(tableId, false); - }); - }; - } - ] - }; - }]); diff --git a/app/components/table/actionbar/component_search_filter/search_filter.js b/app/components/table/actionbar/component_search_filter/search_filter.js deleted file mode 100644 index 4df0c59..0000000 --- a/app/components/table/actionbar/component_search_filter/search_filter.js +++ /dev/null @@ -1,19 +0,0 @@ -'use strict'; - -angular.module('bansho.table.actionbar') - .directive('banshoActionbarSearchFilter', [function () { - return { - restrict: 'E', - scope: { - 'tableId': '=' - }, - templateUrl: 'components/table/actionbar/component_search_filter/search_filter.html', - controller: ['$scope', 'tables', function ($scope, tables) { - $scope.searchFilterChange = function () { - angular.forEach($scope.tableId, function (tableId) { - tables.setSearchFilter(tableId, $scope.searchFilter); - }); - }; - }] - }; - }]); diff --git a/app/components/table/cell_status_duration/cell_status_duration.html b/app/components/table/cell_status_duration/cell_status_duration.html deleted file mode 100644 index e2e535d..0000000 --- a/app/components/table/cell_status_duration/cell_status_duration.html +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/app/components/table/cell_status_event_event_type/cell_status_event_event_type.html b/app/components/table/cell_status_event_event_type/cell_status_event_event_type.html deleted file mode 100644 index 28c23a6..0000000 --- a/app/components/table/cell_status_event_event_type/cell_status_event_event_type.html +++ /dev/null @@ -1,3 +0,0 @@ - -

    {{entry.event_type}}

    - diff --git a/app/components/table/cell_status_event_host_name/cell_status_event_host_name.html b/app/components/table/cell_status_event_host_name/cell_status_event_host_name.html deleted file mode 100644 index ce6f336..0000000 --- a/app/components/table/cell_status_event_host_name/cell_status_event_host_name.html +++ /dev/null @@ -1,3 +0,0 @@ - -

    {{entry.host_name}}

    - diff --git a/app/components/table/cell_status_event_service/cell_status_event_service.html b/app/components/table/cell_status_event_service/cell_status_event_service.html deleted file mode 100644 index e1e994a..0000000 --- a/app/components/table/cell_status_event_service/cell_status_event_service.html +++ /dev/null @@ -1,3 +0,0 @@ - -

    {{entry.service_description}}

    - diff --git a/app/components/table/cell_status_event_time/cell_status_event_time.html b/app/components/table/cell_status_event_time/cell_status_event_time.html deleted file mode 100644 index 420f43f..0000000 --- a/app/components/table/cell_status_event_time/cell_status_event_time.html +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/app/components/table/cell_status_last_check/cell_status_last_check.html b/app/components/table/cell_status_last_check/cell_status_last_check.html deleted file mode 100644 index f13bdc5..0000000 --- a/app/components/table/cell_status_last_check/cell_status_last_check.html +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/app/components/table/cell_status_service_check/cell_status_service_check.html b/app/components/table/cell_status_service_check/cell_status_service_check.html deleted file mode 100644 index 2a34fe3..0000000 --- a/app/components/table/cell_status_service_check/cell_status_service_check.html +++ /dev/null @@ -1,8 +0,0 @@ - -
    -
    - {{entry.service_description}} -
    -
    {{entry.plugin_output}}
    -
    - diff --git a/app/components/table/state_icon/state_icon.js b/app/components/table/state_icon/state_icon.js deleted file mode 100644 index 367a3ce..0000000 --- a/app/components/table/state_icon/state_icon.js +++ /dev/null @@ -1,44 +0,0 @@ -'use strict'; - -angular.module('bansho.table.state_icon', []) - .directive('banshoHostStateIcon', function () { - return { - restrict: 'E', - scope: { - state: '=state' - }, - templateUrl: 'components/table/state_icon/state_icon.html', - controller: ['$scope', function ($scope) { - if ($scope.state === 'UP') { - $scope.stateClass = 'state--ok'; - } else if ($scope.state === 'WARNING') { - $scope.stateClass = 'state--warning'; - } else if ($scope.state === '') { - $scope.stateClass = ''; - } else { - $scope.stateClass = 'state--error'; - } - }] - }; - }) - - .directive('banshoServiceStateIcon', function () { - return { - restrict: 'E', - scope: { - state: '=state' - }, - templateUrl: 'components/table/state_icon/state_icon.html', - controller: ['$scope', function ($scope) { - if ($scope.state === 'OK') { - $scope.stateClass = 'state--ok'; - } else if ($scope.state === 'WARNING') { - $scope.state = 'state--warning'; - } else if ($scope.state === '') { - $scope.stateClass = ''; - } else { - $scope.stateClass = 'state--error'; - } - }] - }; - }); diff --git a/app/components/table/table.html b/app/components/table/table.html deleted file mode 100644 index d82b61b..0000000 --- a/app/components/table/table.html +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - -
    - - - {{cellsText[i]}} - -
    - - - {{cellsText[i]}} - -
    - -
    diff --git a/app/components/tactical/tactical.html b/app/components/tactical/tactical.html deleted file mode 100644 index 2ccf5e4..0000000 --- a/app/components/tactical/tactical.html +++ /dev/null @@ -1,15 +0,0 @@ -
    -
    -
    - -
    - -
    - -
    - -
    - -
    -
    -
    diff --git a/app/components/tactical/tactical.js b/app/components/tactical/tactical.js deleted file mode 100644 index 255299e..0000000 --- a/app/components/tactical/tactical.js +++ /dev/null @@ -1,84 +0,0 @@ -'use strict'; - -angular.module('bansho.tactical', ['bansho.surveil', - 'bansho.utils.promiseManager', - 'bansho.tactical.status_overview', - 'bansho.tactical.current_health', - 'bansho.tactical.top_alert_producers' - ]) - - .value('tacticalConfig', {}) - - .value('TacticalConfigObj', function (config) { - this.title = config.title; - this.statusOverview = config.components.statusOverview; - this.currentHealth = config.components.currentHealth; - this.topAlertProducers = config.components.topAlertProducers; - }) - - .controller('TacticalCtrl', ['$scope', '$interval', 'tacticalConfig', 'surveilStatus', 'promisesManager', - function ($scope, $interval, tacticalConfig, surveilStatus, promisesManager) { - - var getData; - - $scope.statusOverview = tacticalConfig.statusOverview; - $scope.currentHealth = tacticalConfig.currentHealth; - $scope.topAlertProducers = tacticalConfig.topAlertProducers; - - $scope.hostsRatio = undefined; - $scope.servicesRatio = undefined; - $scope.hostProblems = undefined; - $scope.totalHosts = undefined; - $scope.serviceProblems = undefined; - $scope.totalServices = undefined; - - getData = function () { - surveilStatus.getHostProblems().success(function (hostProblems) { - $scope.hostProblems = hostProblems.length; - surveilStatus.getTotalHosts().success(function (allHosts) { - $scope.totalHosts = allHosts.length; - $scope.hostsRatio = ($scope.totalHosts - $scope.hostProblems) / $scope.totalHosts * 100; - }); - }); - - surveilStatus.getServiceProblems().success(function (serviceProblems) { - $scope.serviceProblems = serviceProblems.length; - surveilStatus.getTotalServices().success(function (allServices) { - $scope.totalServices = allServices.length; - $scope.servicesRatio = ($scope.totalServices - $scope.serviceProblems) / $scope.totalServices * 100; - }); - }); - }; - - if (tacticalConfig.refreshInterval !== 0) { - promisesManager.addAjaxPromise( - $interval(getData, tacticalConfig.refreshInterval) - ); - } - - getData(); - - // Togglable tabs - // Don't follow hyperlinks - $('a[data-toggle="tab"]').on('click', function (evt) { - evt.preventDefault(); - }); - }]) - - .directive('banshoTactical', ['tacticalConfig', function (tacticalConfig) { - return { - restrict: 'E', - templateUrl: 'components/tactical/tactical.html', - compile: function compile() { - return { - pre: function preLink(scope, iElement, iAttrs, controller) { - // This is the earliest phase during which attributes are evaluated - tacticalConfig.statusOverview = JSON.parse(iAttrs.statusOverview); - tacticalConfig.currentHealth = JSON.parse(iAttrs.currentHealth); - tacticalConfig.topAlertProducers = JSON.parse(iAttrs.topAlertProducers); - tacticalConfig.refreshInterval = parseInt(iAttrs.refreshInterval * 1000, 10); - } - }; - } - }; - }]); diff --git a/app/components/topbar/topbar.html b/app/components/topbar/topbar.html index f6d55f0..5d5dba2 100644 --- a/app/components/topbar/topbar.html +++ b/app/components/topbar/topbar.html @@ -1,4 +1,4 @@ -
    -
    +
    diff --git a/app/templates/config/config.js b/app/templates/config/config.js index 2af9f29..b492622 100644 --- a/app/templates/config/config.js +++ b/app/templates/config/config.js @@ -2,7 +2,7 @@ 'use strict'; -angular.module('bansho.view.singleTable') +angular.module('bansho.view.config', []) .controller('ConfigCtrl', ['$scope', '$window', 'configManager', function ($scope, $window, configManager) { $scope.configuration = JSON.stringify(configManager.readConfig(),null,4); diff --git a/app/templates/dashboard/dashboard.html b/app/templates/dashboard/dashboard.html deleted file mode 100644 index fe52aba..0000000 --- a/app/templates/dashboard/dashboard.html +++ /dev/null @@ -1,151 +0,0 @@ -
    -
    -

    {{dashboardTactical[0].title}}

    - - - -
    - -
    - - - - -
    -
    - -
    -

    {{dashboardTables[0].title}}

    -

    - There - - - are {{nbHostOpenProblems}} host - - -

    -
    - - - -
    - - -
    -

    {{dashboardTables[1].title}}

    -

    - There - - - {{nbServiceOpenProblems}} service - - -

    -
    - - - -
    -
    - -
    - -
    -

    {{dashboardTables[2].title}}

    -

    - There - - - {{nbHostProblems}} host - - -

    -
    - - -
    - - -
    -

    {{dashboardTables[3].title}}

    -

    - There - - - {{nbServiceProblems}} service - - -

    -
    - - -
    -
    -
    - -
    -
    diff --git a/app/templates/dashboard/dashboard.js b/app/templates/dashboard/dashboard.js deleted file mode 100644 index 95f73bf..0000000 --- a/app/templates/dashboard/dashboard.js +++ /dev/null @@ -1,68 +0,0 @@ -/*global jQuery */ - -'use strict'; - -angular.module('bansho.view.dashboard', ['ngRoute', - 'bansho.utils.promiseManager', - 'bansho.tactical', - 'bansho.table', - 'bansho.surveil' - ]) - - .controller('DashboardCtrl', ['$scope', '$routeParams', '$interval', 'configManager', 'TableConfigObj', 'TacticalConfigObj', 'surveilStatus', 'promisesManager', - function ($scope, $routeParams, $interval, configManager, TableConfigObj, TacticalConfigObj, surveilStatus, promisesManager) { - var components = [], - component, - config, - viewName = $scope.viewName, - pageConfig = configManager.getConfigData(viewName), - i = 0, - getData; - - $scope.dashboardTitle = pageConfig.title; - $scope.dashboardTemplate = pageConfig.template; - $scope.dashboardRefreshInterval = pageConfig.refreshInterval; - - $scope.dashboardTactical = []; - $scope.dashboardTables = []; - - $scope.components = pageConfig.components; - components = pageConfig.extra_components; - - for (i = 0; i < components.length; i += 1) { - component = components[i]; - config = component.config; - - if (component.type === 'table') { - $scope.dashboardTables.push(new TableConfigObj(config)); - } else if (component.type === 'tactical') { - $scope.dashboardTactical.push(new TacticalConfigObj(config)); - } - } - - getData = function () { - surveilStatus.getHostOpenProblems().success(function (data) { - $scope.nbHostOpenProblems = data.length; - surveilStatus.getServiceOpenProblems().then(function (openProblems) { - $scope.nbServiceOpenProblems = openProblems.length; - $scope.totalOpenProblems = $scope.nbServiceOpenProblems + $scope.nbHostOpenProblems; - }); - }); - - surveilStatus.getHostProblems().success(function (data) { - $scope.nbHostProblems = data.length; - surveilStatus.getServiceProblems().success(function (data) { - $scope.nbServiceProblems = data.length; - $scope.totalProblems = $scope.nbHostProblems + $scope.nbServiceProblems; - }); - }); - }; - - if ($scope.dashboardRefreshInterval !== 0) { - promisesManager.addAjaxPromise( - $interval(getData, $scope.dashboardRefreshInterval * 1000) - ); - } - - getData(); - }]); diff --git a/app/templates/host/host.html b/app/templates/host/host.html index 4833e0a..6bbe203 100644 --- a/app/templates/host/host.html +++ b/app/templates/host/host.html @@ -1,3 +1,3 @@
    - +
    diff --git a/app/templates/host/host.js b/app/templates/host/host.js index d992f42..9b8d1fe 100644 --- a/app/templates/host/host.js +++ b/app/templates/host/host.js @@ -1,12 +1,16 @@ 'use strict'; -angular.module('bansho.view.host', ['bansho.surveil']) +angular.module('bansho.view.host', ['bansho.datasource']) - .controller('HostViewCtrl', ['$http', '$scope', '$routeParams', - function ($http, $scope, $routeParams) { - if (!!$routeParams.host_name) { - $scope.hostName = $routeParams.host_name; - } else { + .controller('HostViewCtrl', ['$scope', '$routeParams', 'configManager', 'pageParams', + function ($scope, $routeParams, configManager, pageParams) { + var hostname = $routeParams.host_name; + + $scope.components = configManager.getConfigData($scope.viewName).components; + + if (!hostname) { throw new Error("ERROR :'host_name' GET parameter must be set"); + } else { + pageParams.hostname = hostname; } }]); diff --git a/app/templates/page/page.html b/app/templates/page/page.html new file mode 100644 index 0000000..29c8ec7 --- /dev/null +++ b/app/templates/page/page.html @@ -0,0 +1,3 @@ +
    + +
    diff --git a/app/templates/page/page.js b/app/templates/page/page.js new file mode 100644 index 0000000..3dc45a5 --- /dev/null +++ b/app/templates/page/page.js @@ -0,0 +1,36 @@ +'use strict'; + +angular.module('bansho.view.page', ['bansho.table', 'bansho.tactical']) + + .value('pageParams', {}) + + .controller('PageCtrl', ['$scope', 'configManager', 'pageParams', + function ($scope, configManager, pageParams) { + pageParams.page = configManager.getConfigData($scope.viewName); + $scope.components = pageParams.page.components; + }]) + + .directive('banshoComponents', ['$compile', 'directiveBuilder', function ($compile, directiveBuilder) { + return { + restrict: "E", + scope: { + components: '=' + }, + link: function (scope, element) { + if (angular.isArray(scope.components)) { + angular.forEach(scope.components, function (component, index) { + element.append(directiveBuilder(component.type, index)); + }); + + $compile(element.contents())(scope); + } + } + }; + }]) + + .factory('directiveBuilder', function () { + return function (type, index) { + return ""; + }; + }); + diff --git a/app/templates/service/service.html b/app/templates/service/service.html index 983410f..dc683ab 100644 --- a/app/templates/service/service.html +++ b/app/templates/service/service.html @@ -1,3 +1,3 @@
    - +
    diff --git a/app/templates/service/service.js b/app/templates/service/service.js index a6636cb..b1a6128 100644 --- a/app/templates/service/service.js +++ b/app/templates/service/service.js @@ -2,13 +2,17 @@ angular.module("bansho.view.service", [ "bansho.surveil" ]) - .controller("ServiceViewCtrl", [ "$scope", "$routeParams", - function ($scope, $routeParams) { + .controller("ServiceViewCtrl", ['$scope', '$routeParams', 'configManager', 'pageParams', + function ($scope, $routeParams, configManager, pageParams) { + var host_name = $routeParams.host_name, + service_description = $routeParams.description; - if (!$routeParams.host_name || !$routeParams.description) { + $scope.components = configManager.getConfigData($scope.viewName).components; + + if (!host_name || !service_description) { throw new Error("ERROR :'host_name' and 'description' GET parameters must be set"); + } else { + pageParams.host_name = host_name; + pageParams.service_description = service_description; } - - $scope.hostName = $routeParams.host_name; - $scope.description = $routeParams.description; }]); diff --git a/app/templates/tables/tables.html b/app/templates/tables/tables.html deleted file mode 100644 index ecc5284..0000000 --- a/app/templates/tables/tables.html +++ /dev/null @@ -1,5 +0,0 @@ -
    -
    - -
    -
    diff --git a/app/templates/tables/tables.js b/app/templates/tables/tables.js deleted file mode 100644 index 47ecd07..0000000 --- a/app/templates/tables/tables.js +++ /dev/null @@ -1,58 +0,0 @@ -'use strict'; - -angular.module('bansho.view.singleTable', ['ngRoute', - 'bansho.tactical.status_overview', - 'bansho.tactical.current_health', - 'bansho.tactical.top_alert_producers', - 'bansho.table' - ]) - - .controller('TablesCtrl', ['$scope', 'configManager', - function ($scope, configManager) { - var pageConfig = configManager.getConfigData($scope.viewName); - - $scope.pageTitle = pageConfig.title; - $scope.refresh = pageConfig.refreshInterval; - $scope.components = pageConfig.components; - }]) - - .directive('banshoComponents', ['$compile', function ($compile) { - return { - restrict: "E", - replace: true, - scope: { - components: '=', - refresh: '=' - }, - template: "", - link: function (scope, element, attrs) { - if (angular.isArray(scope.components)) { - angular.forEach(scope.components, function (component) { - var banshoDirective = "