Skip to content

Commit

Permalink
add alerts drop down to provider view
Browse files Browse the repository at this point in the history
Added endpoint prometheus_alerts

minor refactoring

minor refactoring

added some refactoring
  • Loading branch information
nimrodshn committed Aug 21, 2017
1 parent 1929a7f commit c2d3384
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', '
metrics_auth_status: '',
ssh_keypair_auth_status: '',
hawkular_auth_status: '',
vmware_cloud_api_version: ''
vmware_cloud_api_version: '',
prometheus_alerts_hostname: '',
prometheus_alerts_api_port: '',
prometheus_alerts_tls_ca_certs: '',
prometheus_alerts_auth_status: '',
prometheus_alerts_security_protocol: '',
alerts_selection: '',
};
$scope.formId = emsCommonFormId;
$scope.afterGet = false;
Expand Down Expand Up @@ -147,6 +153,12 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', '
$scope.emsCommonModel.metrics_auth_status = data.metrics_auth_status;
$scope.emsCommonModel.ssh_keypair_auth_status = data.ssh_keypair_auth_status;
$scope.emsCommonModel.hawkular_auth_status = data.hawkular_auth_status;
$scope.emsCommonModel.alerts_selection = data.alerts_selection;
$scope.emsCommonModel.prometheus_alerts_hostname = data.prometheus_alerts_hostname;
$scope.emsCommonModel.prometheus_alerts_api_port = data.prometheus_alerts_api_port !== undefined && data.prometheus_alerts_api_port !== '' ? data.prometheus_alerts_api_port.toString() : '443';
$scope.emsCommonModel.prometheus_alerts_auth_status = data.prometheus_alerts_auth_status;
$scope.emsCommonModel.prometheus_alerts_security_protocol = data.prometheus_alerts_security_protocol;
$scope.emsCommonModel.prometheus_alerts_tls_ca_certs = data.prometheus_alerts_tls_ca_certs;

if ($scope.emsCommonModel.default_userid !== '') {
$scope.emsCommonModel.default_password = miqService.storedPasswordPlaceholder;
Expand Down Expand Up @@ -184,6 +196,11 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', '
$scope.emsCommonModel.default_api_port = '';
$scope.emsCommonModel.amqp_api_port = '5672';
$scope.emsCommonModel.metrics_selection = data.metrics_selection;
$scope.emsCommonModel.alerts_selection = data.alerts_selection;
$scope.emsCommonModel.prometheus_alerts_api_port = '443';
$scope.emsCommonModel.prometheus_alerts_auth_status = data.prometheus_alerts_auth_status;
$scope.emsCommonModel.prometheus_alerts_security_protocol = data.prometheus_alerts_security_protocol;
$scope.emsCommonModel.prometheus_alerts_tls_ca_certs = data.prometheus_alerts_tls_ca_certs;
$scope.emsCommonModel.hawkular_api_port = '443';
$scope.emsCommonModel.api_version = 'v2';
$scope.emsCommonModel.ems_controller = data.ems_controller;
Expand Down Expand Up @@ -253,11 +270,16 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', '
($scope.emsCommonModel.default_hostname != '' && $scope.emsCommonModel.default_api_port) &&
($scope.emsCommonModel.default_password != '' && $scope.angularForm.default_password.$valid)) {
return true;
} else if (($scope.currentTab == "alerts" && $scope.emsCommonModel.ems_controller == "ems_container") &&
($scope.emsCommonModel.emstype) &&
($scope.emsCommonModel.prometheus_alerts_hostname != '' && $scope.emsCommonModel.prometheus_alerts_api_port != '') &&
($scope.emsCommonModel.default_password != '' && $scope.angularForm.default_password.$valid)) {
return true;
} else if(($scope.currentTab == "hawkular" && $scope.emsCommonModel.ems_controller == "ems_container") &&
($scope.emsCommonModel.emstype) &&
($scope.emsCommonModel.hawkular_hostname != '' && $scope.emsCommonModel.hawkular_api_port) &&
($scope.emsCommonModel.default_password != '' && $scope.angularForm.default_password.$valid)) {
return true;
return true;
} else if($scope.emsCommonModel.emstype == "gce" && $scope.emsCommonModel.project != '' &&
($scope.currentTab == "default" ||
($scope.currentTab == "service_account" && $scope.emsCommonModel.service_account != ''))) {
Expand Down Expand Up @@ -434,6 +456,9 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', '
if ($scope.emsCommonModel.hawkular_auth_status === true) {
$scope.postValidationModelRegistry("hawkular");
}
if ($scope.emsCommonModel.prometheus_alerts_auth_status === true) {
$scope.postValidationModelRegistry("prometheus_alerts");
}
};

$scope.postValidationModelRegistry = function(prefix) {
Expand All @@ -442,7 +467,9 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', '
amqp: {},
metrics: {},
ssh_keypair: {},
hawkular: {}}
hawkular: {},
prometheus_alerts: {}
}
}
if (prefix === "default") {
if ($scope.newRecord) {
Expand Down Expand Up @@ -510,6 +537,13 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', '
hawkular_security_protocol: $scope.emsCommonModel.hawkular_security_protocol,
hawkular_tls_ca_certs: $scope.emsCommonModel.hawkular_tls_ca_certs,
}
} else if (prefix == "prometheus_alerts") {
$scope.postValidationModel['prometheus_alerts'] = {
prometheus_alerts_hostname: $scope.emsCommonModel.prometheus_alerts_hostname,
prometheus_alerts_api_port: $scope.emsCommonModel.prometheus_alerts_api_port,
prometheus_alerts_security_protocol: $scope.emsCommonModel.prometheus_alerts_security_protocol,
prometheus_alerts_tls_ca_certs: $scope.emsCommonModel.prometheus_alerts_tls_ca_certs,
}
}
};

Expand Down
5 changes: 5 additions & 0 deletions app/controllers/ems_container_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ def retrieve_metrics_selection
@ems.endpoints.count == 1 ? 'hawkular_disabled' : 'hawkular_enabled'
end

def retrieve_alerts_selection
return "disabled" if @ems.connection_configurations.try(:prometheus_alerts).nil?
"prometheus"
end

private

def textual_group_list
Expand Down
90 changes: 60 additions & 30 deletions app/controllers/mixins/ems_common_angular.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ def ems_form_fields
hawkular_api_port = ""
hawkular_security_protocol = security_protocol_default
hawkular_tls_ca_certs = ""
prometheus_alerts_hostname = ""
prometheus_alerts_api_port = ""
prometheus_alerts_security_protocol = security_protocol_default
prometheus_alerts_tls_ca_certs = ""

if @ems.connection_configurations.amqp.try(:endpoint)
amqp_hostname = @ems.connection_configurations.amqp.endpoint.hostname
Expand Down Expand Up @@ -180,6 +184,15 @@ def ems_form_fields
hawkular_tls_ca_certs = @ems.connection_configurations.hawkular.endpoint.certificate_authority
end

if @ems.connection_configurations.prometheus_alerts.try(:endpoint)
prometheus_alerts_hostname = @ems.connection_configurations.prometheus_alerts.endpoint.hostname
prometheus_alerts_api_port = @ems.connection_configurations.prometheus_alerts.endpoint.port
prometheus_alerts_auth_status = @ems.authentication_status_ok?(:alerts)
prometheus_alerts_security_protocol = @ems.connection_configurations.prometheus_alerts.endpoint.security_protocol
prometheus_alerts_security_protocol ||= security_protocol_default
prometheus_alerts_tls_ca_certs = @ems.connection_configurations.prometheus_alerts.endpoint.certificate_authority
end

if @ems.connection_configurations.default.try(:endpoint)
default_hostname = @ems.connection_configurations.default.endpoint.hostname
default_api_port = @ems.connection_configurations.default.endpoint.port
Expand Down Expand Up @@ -273,29 +286,36 @@ def ems_form_fields
:ssh_keypair_auth_status => ssh_keypair_auth_status.nil? ? true : ssh_keypair_auth_status
} if controller_name == "ems_infra"

render :json => {:name => @ems.name,
:emstype => @ems.emstype,
:zone => zone,
:hostname => @ems.hostname,
:default_hostname => @ems.connection_configurations.default.endpoint.hostname,
:metrics_selection => retrieve_metrics_selection,
:metrics_selection_default => @ems.emstype == 'kubernetes' ? 'disabled' : 'enabled',
:hawkular_hostname => hawkular_hostname,
:default_api_port => @ems.connection_configurations.default.endpoint.port,
:hawkular_api_port => hawkular_api_port,
:api_version => @ems.api_version ? @ems.api_version : "v2",
:default_security_protocol => default_security_protocol,
:hawkular_security_protocol => hawkular_security_protocol,
:default_tls_ca_certs => default_tls_ca_certs,
:hawkular_tls_ca_certs => hawkular_tls_ca_certs,
:provider_region => @ems.provider_region,
:default_userid => @ems.authentication_userid ? @ems.authentication_userid : "",
:service_account => service_account ? service_account : "",
:bearer_token_exists => @ems.authentication_token(:bearer).nil? ? false : true,
:ems_controller => controller_name,
:default_auth_status => default_auth_status,
:hawkular_auth_status => hawkular_auth_status,
} if controller_name == "ems_container"
if controller_name == "ems_container"
render :json => {:name => @ems.name,
:emstype => @ems.emstype,
:zone => zone,
:hostname => @ems.hostname,
:default_hostname => @ems.connection_configurations.default.endpoint.hostname,
:metrics_selection => retrieve_metrics_selection,
:metrics_selection_default => @ems.emstype == 'kubernetes' ? 'disabled' : 'enabled',
:hawkular_hostname => hawkular_hostname,
:default_api_port => @ems.connection_configurations.default.endpoint.port,
:hawkular_api_port => hawkular_api_port,
:api_version => @ems.api_version ? @ems.api_version : "v2",
:default_security_protocol => default_security_protocol,
:hawkular_security_protocol => hawkular_security_protocol,
:default_tls_ca_certs => default_tls_ca_certs,
:hawkular_tls_ca_certs => hawkular_tls_ca_certs,
:provider_region => @ems.provider_region,
:default_userid => @ems.authentication_userid ? @ems.authentication_userid : "",
:service_account => service_account ? service_account : "",
:bearer_token_exists => @ems.authentication_token(:bearer).nil? ? false : true,
:ems_controller => controller_name,
:default_auth_status => default_auth_status,
:hawkular_auth_status => hawkular_auth_status,
:prometheus_alerts_api_port => prometheus_alerts_api_port,
:prometheus_alerts_hostname => prometheus_alerts_hostname,
:prometheus_alerts_security_protocol => prometheus_alerts_security_protocol,
:prometheus_alerts_tls_ca_certs => prometheus_alerts_tls_ca_certs,
:prometheus_alerts_auth_status => prometheus_alerts_auth_status,
:alerts_selection => retrieve_alerts_selection}
end

if controller_name == "ems_middleware"
render :json => {:name => @ems.name,
Expand Down Expand Up @@ -368,12 +388,17 @@ def set_ems_record_vars(ems, mode = nil)
hawkular_security_protocol = params[:hawkular_security_protocol].strip if params[:hawkular_security_protocol]
default_tls_ca_certs = params[:default_tls_ca_certs].strip if params[:default_tls_ca_certs]
hawkular_tls_ca_certs = params[:hawkular_tls_ca_certs].strip if params[:hawkular_tls_ca_certs]
prometheus_alerts_tls_ca_certs = params[:prometheus_alerts_tls_ca_certs].strip if params[:prometheus_alerts_tls_ca_certs]
prometheus_alerts_hostname = params[:prometheus_alerts_hostname].strip if params[:prometheus_alerts_hostname]
prometheus_alerts_api_port = params[:prometheus_alerts_api_port].strip if params[:prometheus_alerts_api_port]
prometheus_alerts_security_protocol = params[:prometheus_alerts_security_protocol].strip if params[:prometheus_alerts_security_protocol]
default_endpoint = {}
amqp_endpoint = {}
ceilometer_endpoint = {}
ssh_keypair_endpoint = {}
metrics_endpoint = {}
hawkular_endpoint = {}
prometheus_alerts_endpoint = {}

if ems.kind_of?(ManageIQ::Providers::Openstack::CloudManager) || ems.kind_of?(ManageIQ::Providers::Openstack::InfraManager)
default_endpoint = {:role => :default, :hostname => hostname, :port => port, :security_protocol => ems.security_protocol}
Expand Down Expand Up @@ -437,6 +462,10 @@ def set_ems_record_vars(ems, mode = nil)
hawkular_endpoint = {:role => :hawkular, :hostname => hawkular_hostname, :port => hawkular_api_port}
hawkular_endpoint.merge!(endpoint_security_options(hawkular_security_protocol, hawkular_tls_ca_certs))
end
if params[:alerts_selection] == 'prometheus'
prometheus_alerts_endpoint = {:role => :prometheus_alerts, :hostname => prometheus_alerts_hostname, :port => prometheus_alerts_api_port}
prometheus_alerts_endpoint.merge!(endpoint_security_options(prometheus_alerts_security_protocol, prometheus_alerts_tls_ca_certs))
end
end

if ems.kind_of?(ManageIQ::Providers::MiddlewareManager)
Expand All @@ -457,12 +486,13 @@ def set_ems_record_vars(ems, mode = nil)
default_endpoint = {:role => :default, :hostname => hostname, :port => port}
end

endpoints = {:default => default_endpoint,
:ceilometer => ceilometer_endpoint,
:amqp => amqp_endpoint,
:ssh_keypair => ssh_keypair_endpoint,
:metrics => metrics_endpoint,
:hawkular => hawkular_endpoint}
endpoints = {:default => default_endpoint,
:ceilometer => ceilometer_endpoint,
:amqp => amqp_endpoint,
:ssh_keypair => ssh_keypair_endpoint,
:metrics => metrics_endpoint,
:hawkular => hawkular_endpoint,
:prometheus_alerts => prometheus_alerts_endpoint}

build_connection(ems, endpoints, mode)
end
Expand All @@ -479,7 +509,7 @@ def build_connection(ems, endpoints, mode)
authentications = build_credentials(ems, mode)
configurations = []

[:default, :ceilometer, :amqp, :ssh_keypair, :metrics, :hawkular].each do |role|
[:default, :ceilometer, :amqp, :ssh_keypair, :metrics, :hawkular, :prometheus_alerts].each do |role|
configurations << build_configuration(ems, authentications, endpoints, role)
end

Expand Down
9 changes: 9 additions & 0 deletions app/views/ems_container/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@
"checkchange" => "",
"required" => "",
"selectpicker-for-select-tag" => "")
.form-group{"ng-class" => "{'has-error': angularForm.alerts.$invalid}"}
%label.col-md-2.control-label{"for" => "prov_alerts"}
= _("Alerts")
.col-md-8
= select_tag('alerts_selection', options_for_select([[_("Disabled"), "disabled"], [_("Prometheus"), "prometheus"]]),
"ng-model" => "emsCommonModel.alerts_selection",
"checkchange" => "",
"required" => "",
"selectpicker-for-select-tag" => "")
%hr
= render :partial => "layouts/angular/multi_auth_credentials", :locals => {:record => @ems, :ng_model => "emsCommonModel"}
Expand Down
26 changes: 26 additions & 0 deletions app/views/layouts/angular/_multi_auth_credentials.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
= miq_tab_header('hawkular', nil, {'ng-click' => "changeAuthTab('hawkular')"}) do
%i{"error-on-tab" => "hawkular", :style => "color:#cc0000"}
= _("Hawkular")
= miq_tab_header('alerts', nil, 'ng-click' => "changeAuthTab('alerts')") do
%div{"ng-if" => "emsCommonModel.alerts_selection == 'prometheus'"}
%i{"error-on-tab" => "alerts", :style => "color:#cc0000"}
= _("Alerts")
- elsif controller_name == "host"
= miq_tab_header('remote', nil, {'ng-click' => "changeAuthTab('remote')"}) do
= _("Remote Login")
Expand Down Expand Up @@ -300,6 +304,28 @@
.col-md-12
%span{:style => "color:black"}
= _("Used to gather Capacity & Utilization metrics.")
= miq_tab_content('alerts', 'default') do
%div{"ng-if" => "emsCommonModel.alerts_selection == 'prometheus'"}
.form-group
.col-md-12
= render :partial => "layouts/angular-bootstrap/endpoints_angular",
:locals => {:ng_show => true,
:ng_model => ng_model.to_s,
:id => record.id,
:ng_reqd_hostname => "true",
:ng_reqd_api_port => "true",
:prefix => "prometheus_alerts"}
= render :partial => "layouts/angular-bootstrap/auth_credentials_angular_bootstrap",
:locals => {:ng_show => true,
:ng_model => ng_model.to_s,
:main_scope => main_scope,
:ng_show_userid => "false",
:ng_show_password => "false",
:validate_url => validate_url,
:id => record.id,
:prefix => "prometheus_alerts",
:verify_title_off => _("prometheus URL and API port fields are needed to perform validation."),
:basic_info_needed => true}
- elsif controller_name == "host"
= miq_tab_content('remote', 'default') do
.form-group
Expand Down

0 comments on commit c2d3384

Please sign in to comment.