Browse Source

added healthchecks import to plugin

CauseFX 4 years ago
parent
commit
258560782f

+ 6 - 0
api/plugins/healthChecks/healthchecks.css

@@ -0,0 +1,6 @@
+#HEALTHCHECKS-settings-items [id*="Services"] .row.m-b-40 {
+    background: #333;
+    margin: 10px;
+    padding: 10px;
+    border-radius: 5px;
+}

+ 41 - 0
api/plugins/healthChecks/plugin.php

@@ -68,6 +68,47 @@ class HealthChecks extends Organizr
 					'placeholder' => 'HealthChecks Ping URL'
 				),
 			),
+			'Connection' => array(
+				array(
+					'type' => 'input',
+					'name' => 'healthChecksURL',
+					'label' => 'URL',
+					'value' => $this->config['healthChecksURL'],
+					'help' => 'URL for HealthChecks API',
+					'placeholder' => 'HealthChecks API URL'
+				),
+				array(
+					'type' => 'password-alt',
+					'name' => 'healthChecksToken',
+					'label' => 'Token',
+					'value' => $this->config['healthChecksToken']
+				),
+				array(
+					'type' => 'html',
+					'label' => '',
+					'override' => 12,
+					'html' => '
+						<div class="row">
+						    <div class="col-lg-12">
+						        <div class="panel panel-info">
+						            <div class="panel-heading">
+						                <span lang="en">ATTENTION</span>
+						            </div>
+						            <div class="panel-wrapper collapse in" aria-expanded="true">
+						                <div class="panel-body">
+						                	<h4 lang="en">This is only used for the import button...</h4>
+						                    <br/>
+						                    <span>
+						                    	<span lang="en">Make sure to save before using the import button on Services tab</span>
+						                    </span>
+						                </div>
+						            </div>
+						        </div>
+						    </div>
+						</div>
+						'
+				)
+			),
 			'Services' => array(
 				array(
 					'type' => 'arrayMultiple',

+ 54 - 1
api/plugins/healthChecks/settings.js

@@ -13,7 +13,7 @@ $(document).on('click', '#HEALTHCHECKS-settings-button', function() {
         $('#HEALTHCHECKS-settings-items').html(buildFormGroup(response.data));
         var elAddButtonStart = $('#HEALTHCHECKS-settings-page [id*="Services"] .row.start');
         var items = $('#HEALTHCHECKS-settings-page [id*="Services"] .row.m-b-40 span');
-        $(elAddButtonStart).after('<div class="row"><button type="button" class="btn btn-info pull-right m-r-20 addNewHCService" ><i class="fa fa-plus"></i> Add New Service</button></div>');
+        $(elAddButtonStart).after('<div class="row"><button type="button" class="btn btn-info pull-right m-r-20 addNewHCService" ><i class="fa fa-plus"></i> Add New Service</button><button type="button" class="btn btn-primary pull-right m-r-20 importNewHCService" ><i class="fa fa-database"></i> Import Services</button></div>');
         $.each(items, function(key,val) {
             var el = $(val);
             var text = el.text();
@@ -26,6 +26,59 @@ $(document).on('click', '#HEALTHCHECKS-settings-button', function() {
     });
     ajaxloader();
 });
+$(document).on('click', '.importNewHCService', function() {
+	messageSingle('',' Grabbing checks...',activeInfo.settings.notifications.position,'#FFF','info','10000');
+	var apiUrl = 'api/v2/homepage/healthchecks';
+	organizrAPI2('GET',apiUrl).success(function(data) {
+		try {
+			let response = data.response;
+			if(response.data !== null){
+				if(response.data === false){ return ''; }
+				let checks = (typeof response.data.content.checks !== 'undefined') ? response.data.content.checks : false;
+				if(checks){
+					let checksAlreadySetup = $('#HEALTHCHECKS-settings-page').serializeToJSON();
+					if(typeof checksAlreadySetup['HEALTHCHECKS-all-items'] !== 'undefined'){
+						checksAlreadySetup = checksAlreadySetup['HEALTHCHECKS-all-items'];
+					}else{
+						checksAlreadySetup = null;
+					}
+					$.each(checks, function(i,v) {
+						let alreadySetup = false;
+						let uuid = v.ping_url;
+						uuid = uuid.match(/([0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12})/g);
+						uuid = uuid[0];
+						if(uuid){
+							if(checksAlreadySetup){
+								$.each(checksAlreadySetup, function(index,val) {
+									if(val.uuid == uuid){
+										alreadySetup = true;
+									}
+								});
+							}
+							if(alreadySetup == false){
+								$('.addNewHCService').click();
+								let nameElement = $('#HEALTHCHECKS-settings-page [name*="HEALTHCHECKS-all-items"]').eq(-6).attr('name');
+								let uuidElement = $('#HEALTHCHECKS-settings-page [name*="HEALTHCHECKS-all-items"]').eq(-5).attr('name');
+								$('#HEALTHCHECKS-settings-page [name*="'+nameElement+'"]').val(v.name);
+								$('#HEALTHCHECKS-settings-page [name*="'+uuidElement+'"]').val(uuid);
+								$('#HEALTHCHECKS-settings-page [name*="HEALTHCHECKS-all-items"]').eq(-6).parent().parent().parent().parent().attr('style', 'background: #707cd2; color:white');
+							}else{
+								console.log(v.name + ' is ALREADY SETUP');
+							}
+						}
+					});
+					messageSingle('Import',' Import has completed...',activeInfo.settings.notifications.position,'#FFF','info','10000');
+				}else{
+					messageSingle('',' No HealthChecks were setup',activeInfo.settings.notifications.position,'#FFF','error','10000');
+				}
+			}
+		}catch(e) {
+			organizrCatchError(e,data);
+		}
+	}).fail(function(xhr) {
+		OrganizrApiError(xhr);
+	});
+});
 $(document).on('click', '.addNewHCService', function() {
     var lastEl = $('#HEALTHCHECKS-settings-page [name*="HEALTHCHECKS-all-items"]').last().attr('name');
     var newNum = 0;