10 changed files with 364 additions and 8111 deletions
			
			
		
								
									
										File diff suppressed because it is too large
									
								
							
						
					| @ -0,0 +1,102 @@ | |||||
|  | const { checkStatusCode } = require("../util-server"); | ||||
|  | const { UP } = require("../../src/util"); | ||||
|  | const get = require("lodash.get"); | ||||
|  | 
 | ||||
|  | function validateMonitorChecks(res, checks, bean) { | ||||
|  |     const responseText = typeof data === "string" ? res.data : JSON.stringify(res.data); | ||||
|  |     let checkObj; | ||||
|  | 
 | ||||
|  |     this.checks.forEach(check => { | ||||
|  |         switch (check.type) { | ||||
|  |             case "HTTP_STATUS_CODE_SHOULD_EQUAL": | ||||
|  |                 if (checkStatusCode(res.status, check.value)) { | ||||
|  |                     bean.msg += `, status matches '${check.value}'` | ||||
|  |                     bean.status = UP; | ||||
|  |                 } else { | ||||
|  |                     throw new Error(bean.msg + ", but status code dit not match " + check.value) | ||||
|  |                 } | ||||
|  |                 break; | ||||
|  | 
 | ||||
|  |             case "RESPONSE_SHOULD_CONTAIN_TEXT": | ||||
|  |                 if (responseText.includes(check.value)) { | ||||
|  |                     bean.msg += `, response contains '${check.value}'` | ||||
|  |                     bean.status = UP; | ||||
|  |                 } else { | ||||
|  |                     throw new Error(bean.msg + ", but response does not contain '" + check.value + "'"); | ||||
|  |                 } | ||||
|  |                 break; | ||||
|  | 
 | ||||
|  |             case "RESPONSE_SHOULD_NOT_CONTAIN_TEXT": | ||||
|  |                 if (!responseText.includes(check.value)) { | ||||
|  |                     bean.msg += `, response does not contain '${check.value}'` | ||||
|  |                     bean.status = UP; | ||||
|  |                 } else { | ||||
|  |                     throw new Error(bean.msg + ", but response does contain '" + check.value + "'"); | ||||
|  |                 } | ||||
|  |                 break; | ||||
|  | 
 | ||||
|  |             case "RESPONSE_SHOULD_MATCH_REGEX": | ||||
|  |                 if (responseText.test(new RegExp(check.value))) { | ||||
|  |                     bean.msg += `, regex '${check.value}' matches` | ||||
|  |                     bean.status = UP; | ||||
|  |                 } else { | ||||
|  |                     throw new Error(bean.msg + ", but response does not match regex: '" + check.value + "'"); | ||||
|  |                 } | ||||
|  |                 break; | ||||
|  | 
 | ||||
|  |             case "RESPONSE_SHOULD_NOT_MATCH_REGEX": | ||||
|  |                 if (!responseText.test(new RegExp(check.value))) { | ||||
|  |                     bean.msg += `, regex '${check.value}' does not matches` | ||||
|  |                     bean.status = UP; | ||||
|  |                 } else { | ||||
|  |                     throw new Error(bean.msg + ", but response does match regex: '" + check.value + "'"); | ||||
|  |                 } | ||||
|  |                 break; | ||||
|  | 
 | ||||
|  |             case "RESPONSE_SELECTOR_SHOULD_EQUAL": | ||||
|  |                 checkObj = JSON.parse(check.value); | ||||
|  |                 if (get(res, checkObj.selector) === checkObj.value) { | ||||
|  |                     bean.msg += `, response selector equals '${checkObj.value}'` | ||||
|  |                     bean.status = UP; | ||||
|  |                 } else { | ||||
|  |                     throw new Error(`${bean.msg}, but response selector '${checkObj.selector}' does not equal '${checkObj.value}'`); | ||||
|  |                 } | ||||
|  |                 break; | ||||
|  | 
 | ||||
|  |             case "RESPONSE_SELECTOR_SHOULD_NOT_EQUAL": | ||||
|  |                 checkObj = JSON.parse(check.value); | ||||
|  |                 if (get(res, checkObj.selector) !== checkObj.value) { | ||||
|  |                     bean.msg += `, response selector does not equal '${checkObj.value}'` | ||||
|  |                     bean.status = UP; | ||||
|  |                 } else { | ||||
|  |                     throw new Error(`${bean.msg}, but response selector '${checkObj.selector}' does equal '${checkObj.value}'`); | ||||
|  |                 } | ||||
|  |                 break; | ||||
|  | 
 | ||||
|  |             case "RESPONSE_SELECTOR_SHOULD_MATCH_REGEX": | ||||
|  |                 checkObj = JSON.parse(check.value); | ||||
|  |                 if (get(res, checkObj.selector).test(new RegExp(checkObj.value))) { | ||||
|  |                     bean.msg += `, response selector matches regex '${checkObj.value}'` | ||||
|  |                     bean.status = UP; | ||||
|  |                 } else { | ||||
|  |                     throw new Error(`${bean.msg}, but response selector '${checkObj.selector}' does not match regex '${checkObj.value}'`); | ||||
|  |                 } | ||||
|  |                 break; | ||||
|  | 
 | ||||
|  |             case "RESPONSE_SELECTOR_SHOULD_NOT_MATCH_REGEX": | ||||
|  |                 checkObj = JSON.parse(check.value); | ||||
|  |                 if (!get(res, checkObj.selector).test(new RegExp(checkObj.value))) { | ||||
|  |                     bean.msg += `, response selector does not match regex '${checkObj.value}'` | ||||
|  |                     bean.status = UP; | ||||
|  |                 } else { | ||||
|  |                     throw new Error(`${bean.msg}, but response selector '${checkObj.selector}' does match regex '${checkObj.value}'`); | ||||
|  |                 } | ||||
|  |                 break; | ||||
|  | 
 | ||||
|  |             default: | ||||
|  |                 throw new Error(`${bean.msg}, encountered unknown monitor_check.type`); | ||||
|  |         } | ||||
|  |     }); | ||||
|  | } | ||||
|  | 
 | ||||
|  | module.exports = validateMonitorChecks; | ||||
| @ -0,0 +1,141 @@ | |||||
|  | <template> | ||||
|  |     <div class="monitor-check mb-4"> | ||||
|  |         <div> | ||||
|  |             <select id="type" v-model="monitorCheck.type" :class="{'form-select': true, 'mb-1': !!monitorCheck.type}"> | ||||
|  |                 <option value="HTTP_STATUS_CODE_SHOULD_EQUAL"> | ||||
|  |                     {{ $t("HTTP status code should equal") }} | ||||
|  |                 </option> | ||||
|  |                 <option value="RESPONSE_SHOULD_CONTAIN_TEXT"> | ||||
|  |                     {{ $t("Response should contain text") }} | ||||
|  |                 </option> | ||||
|  |                 <option value="RESPONSE_SHOULD_NOT_CONTAIN_TEXT"> | ||||
|  |                     {{ $t("Response should not contain text") }} | ||||
|  |                 </option> | ||||
|  |                 <option value="RESPONSE_SHOULD_MATCH_REGEX"> | ||||
|  |                     {{ $t("Response should match regex") }} | ||||
|  |                 </option> | ||||
|  |                 <option value="RESPONSE_SHOULD_NOT_MATCH_REGEX"> | ||||
|  |                     {{ $t("Response should not match regex") }} | ||||
|  |                 </option> | ||||
|  |                 <option value="RESPONSE_SELECTOR_SHOULD_EQUAL"> | ||||
|  |                     {{ $t("Response selector should equal") }} | ||||
|  |                 </option> | ||||
|  |                 <option value="RESPONSE_SELECTOR_SHOULD_NOT_EQUAL"> | ||||
|  |                     {{ $t("Response selector should not equal") }} | ||||
|  |                 </option> | ||||
|  |                 <option value="RESPONSE_SELECTOR_SHOULD_MATCH_REGEX"> | ||||
|  |                     {{ $t("Response selector should match regex") }} | ||||
|  |                 </option> | ||||
|  |                 <option value="RESPONSE_SELECTOR_SHOULD_NOT_MATCH_REGEX"> | ||||
|  |                     {{ $t("Response selector should not match regex") }} | ||||
|  |                 </option> | ||||
|  |             </select> | ||||
|  |             <div v-if="monitorCheck.type === 'HTTP_STATUS_CODE_SHOULD_EQUAL'"> | ||||
|  |                 <VueMultiselect | ||||
|  |                     id="acceptedStatusCodes" | ||||
|  |                     v-model="monitorCheck.value" | ||||
|  |                     :options="acceptedStatusCodeOptions" | ||||
|  |                     :multiple="true" | ||||
|  |                     :close-on-select="false" | ||||
|  |                     :clear-on-select="false" | ||||
|  |                     :preserve-search="true" | ||||
|  |                     placeholder="Pick Accepted Status Codes..." | ||||
|  |                     :preselect-first="false" | ||||
|  |                     :max-height="600" | ||||
|  |                     :taggable="true" | ||||
|  |                 ></VueMultiselect> | ||||
|  |             </div> | ||||
|  |             <div v-if="monitorCheck.type === 'RESPONSE_SHOULD_CONTAIN_TEXT' || monitorCheck.type === 'RESPONSE_SHOULD_NOT_CONTAIN_TEXT'"> | ||||
|  |                 <input v-model="monitorCheck.value" type="text" class="form-control" required :placeholder="$t('Value')"> | ||||
|  |             </div> | ||||
|  |             <div v-if="monitorCheck.type === 'RESPONSE_SHOULD_MATCH_REGEX' || monitorCheck.type === 'RESPONSE_SHOULD_NOT_MATCH_REGEX'"> | ||||
|  |                 <input v-model="monitorCheck.value" type="text" class="form-control" required | ||||
|  |                        :placeholder="$t('Regexp, Example: [a-z0-9.]+@gmail\.com')"> | ||||
|  |             </div> | ||||
|  |             <div | ||||
|  |                 v-if="monitorCheck.type === 'RESPONSE_SELECTOR_SHOULD_EQUAL' || monitorCheck.type === 'RESPONSE_SELECTOR_SHOULD_NOT_EQUAL'"> | ||||
|  |                 <input v-model="monitorCheck.value.selector" type="text" class="form-control mb-1" required | ||||
|  |                        :placeholder="$t('Selector, Example: customer.address.street')"> | ||||
|  |                 <input v-model="monitorCheck.value.value" type="text" class="form-control" required :placeholder="$t('Value, Example: First street')"> | ||||
|  |             </div> | ||||
|  |             <div | ||||
|  |                 v-if="monitorCheck.type === 'RESPONSE_SELECTOR_SHOULD_MATCH_REGEX' || monitorCheck.type === 'RESPONSE_SELECTOR_SHOULD_NOT_MATCH_REGEX'"> | ||||
|  |                 <input v-model="monitorCheck.value.selector" type="text" class="form-control mb-1" required | ||||
|  |                        :placeholder="$t('Selector, Example: customer.contactInfo.email')"> | ||||
|  |                 <input v-model="monitorCheck.value.value" type="text" class="form-control" required | ||||
|  |                        :placeholder="$t('Regexp, Example: [a-z0-9.]+@gmail\.com')"> | ||||
|  |             </div> | ||||
|  |         </div> | ||||
|  |         <button class="btn btn-outline-danger" type="button" @click="deleteMonitorCheck"> | ||||
|  |             <font-awesome-icon icon="times" /> | ||||
|  |         </button> | ||||
|  |     </div> | ||||
|  | </template> | ||||
|  | 
 | ||||
|  | <script> | ||||
|  | import VueMultiselect from "vue-multiselect"; | ||||
|  | 
 | ||||
|  | export default { | ||||
|  |     components: { | ||||
|  |         VueMultiselect, | ||||
|  |     }, | ||||
|  |     props: { | ||||
|  |         monitorCheck: { | ||||
|  |             type: Object, | ||||
|  |         }, | ||||
|  |     }, | ||||
|  |     data() { | ||||
|  |         return { | ||||
|  |             acceptedStatusCodeOptions: [], | ||||
|  |         } | ||||
|  |     }, | ||||
|  |     mounted() { | ||||
|  |         let acceptedStatusCodeOptions = [ | ||||
|  |             "100-199", | ||||
|  |             "200-299", | ||||
|  |             "300-399", | ||||
|  |             "400-499", | ||||
|  |             "500-599", | ||||
|  |         ]; | ||||
|  | 
 | ||||
|  |         for (let i = 100; i <= 999; i++) { | ||||
|  |             acceptedStatusCodeOptions.push(i.toString()); | ||||
|  |         } | ||||
|  | 
 | ||||
|  |         this.acceptedStatusCodeOptions = acceptedStatusCodeOptions; | ||||
|  |     }, | ||||
|  |     methods: { | ||||
|  |         deleteMonitorCheck() { | ||||
|  |             this.$emit('delete'); | ||||
|  |         }, | ||||
|  |     }, | ||||
|  | } | ||||
|  | </script> | ||||
|  | 
 | ||||
|  | <style lang="scss" scoped> | ||||
|  | @import "../assets/vars.scss"; | ||||
|  | 
 | ||||
|  | .monitor-check { | ||||
|  |     display: flex; | ||||
|  | 
 | ||||
|  |     input, | ||||
|  |     select { | ||||
|  |         border-radius: 19px 0 0 19px; | ||||
|  |     } | ||||
|  |      | ||||
|  |     button { | ||||
|  |         margin-left: 0.25rem; | ||||
|  |         padding-left: 15px; | ||||
|  |         padding-right: 15px; | ||||
|  |         border-radius: 0 19px 19px 0; | ||||
|  |     } | ||||
|  | } | ||||
|  | </style> | ||||
|  | 
 | ||||
|  | <style lang="scss"> | ||||
|  | .monitor-check { | ||||
|  |     .multiselect__tags { | ||||
|  |         border-radius: 19px 0 0 19px; | ||||
|  |     } | ||||
|  | } | ||||
|  | </style> | ||||
| @ -1,10 +1,10 @@ | |||||
| import { library } from "@fortawesome/fontawesome-svg-core" | import { library } from "@fortawesome/fontawesome-svg-core" | ||||
| import { faCog, faEdit, faPlus, faPause, faPlay, faTachometerAlt, faTrash, faList, faArrowAltCircleUp, faEye, faEyeSlash } from "@fortawesome/free-solid-svg-icons" | import { faCog, faEdit, faPlus, faPause, faPlay, faTachometerAlt, faTrash, faList, faArrowAltCircleUp, faEye, faEyeSlash, faTimes } from "@fortawesome/free-solid-svg-icons" | ||||
| //import { fa } from '@fortawesome/free-regular-svg-icons'
 | //import { fa } from '@fortawesome/free-regular-svg-icons'
 | ||||
| import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome" | import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome" | ||||
| 
 | 
 | ||||
| // Add Free Font Awesome Icons here
 | // Add Free Font Awesome Icons here
 | ||||
| // https://fontawesome.com/v5.15/icons?d=gallery&p=2&s=solid&m=free
 | // https://fontawesome.com/v5.15/icons?d=gallery&p=2&s=solid&m=free
 | ||||
| library.add(faCog, faEdit, faPlus, faPause, faPlay, faTachometerAlt, faTrash, faList, faArrowAltCircleUp, faEye, faEyeSlash); | library.add(faCog, faEdit, faPlus, faPause, faPlay, faTachometerAlt, faTrash, faList, faArrowAltCircleUp, faEye, faEyeSlash, faTimes); | ||||
| 
 | 
 | ||||
| export { FontAwesomeIcon } | export { FontAwesomeIcon } | ||||
|  | |||||
					Loading…
					
					
				
		Reference in new issue