1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | 1 1 1 1 4 20 20 1 1 1 2 2 18 18 18 18 1 18 1 1 4 4 4 10 10 10 4 4 1 1 1 1 1 1 1 1 1 1 1 1 1 | 'use strict'; ;require.register("models/alerts/alert_definition", function (exports, require, module) { /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var App = require('app'); var dateUtils = require('utils/date/date'); function computedOnSummaryState(state) { return Em.computed('summary.' + state, 'summary.' + state + '.count', 'summary.' + state + '.maintenanceCount', function () { var summary = Em.get(this, 'summary'); return !!summary[state] && !!(summary[state].count || summary[state].maintenanceCount); }); } App.AlertDefinition = DS.Model.extend({ name: DS.attr('string'), label: DS.attr('string'), description: DS.attr('string'), service: DS.belongsTo('App.Service'), serviceName: DS.attr('string'), componentName: DS.attr('string'), enabled: DS.attr('boolean'), repeat_tolerance_enabled: DS.attr('boolean'), repeat_tolerance: DS.attr('number'), scope: DS.attr('string'), interval: DS.attr('number'), type: DS.attr('string'), helpUrl: DS.attr('string'), groups: DS.hasMany('App.AlertGroup'), reporting: DS.hasMany('App.AlertReportDefinition'), parameters: DS.hasMany('App.AlertDefinitionParameter'), lastTriggered: 0, lastTriggeredRaw: 0, //relates only to SCRIPT-type alert definition location: DS.attr('string'), //relates only to AGGREGATE-type alert definition alertName: DS.attr('string'), //relates only to WEB and METRIC types of alert definition uri: DS.belongsTo('App.AlertMetricsUriDefinition'), //relates only METRIC-type alert definition jmx: DS.belongsTo('App.AlertMetricsSourceDefinition'), ganglia: DS.belongsTo('App.AlertMetricsSourceDefinition'), ams: DS.belongsTo('App.AlertMetricsAmsDefinition'), //relates only PORT-type alert definition defaultPort: DS.attr('number'), portUri: DS.attr('string'), /** * Raw data from AlertDefinition/source * used to format request content for updating alert definition * @type {Object} */ rawSourceData: {}, /** * Counts of alert grouped by their status * Format: * <code> * { * "CRITICAL": { * count: 1, * maintenanceCount: 0 * }, * "OK": { * count: 0, * maintenanceCount: 1 * }, * "UNKNOWN": { * count: 0, * maintenanceCount: 0 * }, * "WARNING": { * count: 1, * maintenanceCount: 1 * } * } * </code> * @type {object} */ summary: {}, /** * Formatted timestamp for latest alert triggering for current alertDefinition * @type {string} */ lastTriggeredFormatted: function () { var lastTriggered = this.get('lastTriggered'); return lastTriggered ? dateUtils.dateFormat(lastTriggered) : ''; }.property('lastTriggered'), /** * Formatted timestamp with <code>$.timeago</code> * @type {string} */ lastTriggeredAgoFormatted: function () { var lastTriggered = this.get('lastTriggeredRaw'); return lastTriggered ? $.timeago(new Date(lastTriggered)) : ''; }.property('lastTriggeredRaw'), lastTriggeredVerboseDisplay: function () { var lastTriggered = this.get('lastTriggered'); return Em.I18n.t('models.alert_definition.triggered.verbose').format(dateUtils.dateFormat(lastTriggered)); }.property('lastTriggered'), /** * Formatted timestamp in format: for 4 days * @type {string} */ lastTriggeredForFormatted: function () { var lastTriggered = this.get('lastTriggeredRaw'); var previousSuffixAgo = $.timeago.settings.strings.suffixAgo; var previousPrefixAgo = $.timeago.settings.strings.prefixAgo; $.timeago.settings.strings.suffixAgo = null; $.timeago.settings.strings.prefixAgo = 'for'; var triggeredFor = lastTriggered ? $.timeago(new Date(lastTriggered)) : ''; $.timeago.settings.strings.suffixAgo = previousSuffixAgo; $.timeago.settings.strings.prefixAgo = previousPrefixAgo; return triggeredFor; }.property('lastTriggeredRaw'), /** * Formatted displayName for <code>componentName</code> * @type {String} */ componentNameFormatted: Em.computed.formatRole('componentName', false), hostCnt: function () { var order = this.get('order'), summary = this.get('summary'), hostCnt = 0; order.forEach(function (state) { hostCnt += summary[state] ? summary[state].count + summary[state].maintenanceCount : 0; }); return hostCnt; }.property('order', 'summary'), latestText: function () { var order = this.get('order'), summary = this.get('summary'), text = ''; order.forEach(function (state) { var cnt = summary[state] ? summary[state].count + summary[state].maintenanceCount : 0; if (cnt > 0) { text = Em.getWithDefault(summary[state], 'latestText', ''); } }); return text; }.property('summary'), latestTextSummary: function () { var latestText = this.get('latestText'); var ellipsis = '...'; var summaryLength = 400; if (latestText.length > summaryLength) { latestText = latestText.substring(0, summaryLength - ellipsis.length) + ellipsis; } return latestText; }.property('latestText'), isAmbariService: Em.computed.equal('service._id', 'AMBARI'), isAmbariAgentComponent: Em.computed.equal('componentName', 'AMBARI_AGENT'), isHostAlertDefinition: Em.computed.and('isAmbariService', 'isAmbariAgentComponent'), typeIconClass: Em.computed.getByKey('typeIcons', 'type'), isTypeAggregate: Em.computed.equal('type', 'AGGREGATE'), /** * if this definition is in state: CRITICAL / WARNING, if true, will show up in alerts fast access popup * instances with maintenance mode ON are ignored * @type {boolean} */ isCriticalOrWarning: Em.computed.or('summary.CRITICAL.count', 'summary.WARNING.count'), /** * if this definition is in state: CRITICAL * @type {boolean} */ isCritical: computedOnSummaryState('CRITICAL'), /** * if this definition is in state: WARNING * @type {boolean} */ isWarning: computedOnSummaryState('WARNING'), /** * if this definition is in state: OK * @type {boolean} */ isOK: computedOnSummaryState('OK'), /** * if this definition is in state: UNKNOWN * @type {boolean} */ isUnknown: computedOnSummaryState('UNKNOWN'), /** * For alerts we will have processes which are not typical * cluster services - like Ambari-Server. This method unifies * cluster services and other services into a common display-name. * @see App.AlertInstance#serviceDisplayName() */ serviceDisplayName: function () { var serviceName = this.get('service.displayName'); Eif (!serviceName) { serviceName = this.get('serviceName'); if (serviceName) { serviceName = serviceName.toCapital(); } } return serviceName; }.property('serviceName', 'service.displayName'), /** * Determines if alert definition has help url * @type {boolean} */ hasHelpUrl: Em.computed.bool('helpUrl'), /** * List of css-classes for alert types * @type {object} */ typeIcons: { 'METRIC': 'glyphicon glyphicon-flash', 'SCRIPT': 'glyphicon glyphicon-file', 'WEB': 'glyphicon glyphicon-globe', 'PORT': 'glyphicon glyphicon-log-in', 'AGGREGATE': 'glyphicon glyphicon-plus', 'SERVER': 'glyphicon glyphicon-oil', 'RECOVERY': 'glyphicon glyphicon-oil', 'AMS': 'glyphicon glyphicon-stats' }, /** * Sort on load definitions by this severity order */ severityOrder: ['CRITICAL', 'WARNING', 'OK', 'UNKNOWN', 'PENDING'], order: ['OK', 'WARNING', 'CRITICAL', 'UNKNOWN'] }); App.AlertDefinition.shortState = { 'CRITICAL': 'CRIT', 'WARNING': 'WARN', 'OK': 'OK', 'UNKNOWN': 'UNKWN', 'PENDING': 'NONE' }; App.AlertDefinition.reopenClass({ /** * Return function to sort list of AlertDefinitions by their status * It sorts according to <code>severityOrder</code> * @param {boolean} order true - DESC, false - ASC * @returns {Function} * @method getSortDefinitionsByStatus */ getSortDefinitionsByStatus: function getSortDefinitionsByStatus(order) { return function (a, b) { var aSummary = a.get('summary'), bSummary = b.get('summary'), stOrder = a.get('severityOrder'), ret = 0; for (var i = 0; i < stOrder.length; i++) { var aV = Em.isNone(aSummary[stOrder[i]]) ? 0 : aSummary[stOrder[i]].count + aSummary[stOrder[i]].maintenanceCount, bV = Em.isNone(bSummary[stOrder[i]]) ? 0 : bSummary[stOrder[i]].count + bSummary[stOrder[i]].maintenanceCount; ret = bV - aV; if (ret !== 0) { break; } } return order ? ret : -ret; }; } }); App.AlertDefinitionParameter = DS.Model.extend({ name: DS.attr('string'), displayName: DS.attr('string'), units: DS.attr('string'), value: DS.attr('string'), description: DS.attr('string'), type: DS.attr('string'), threshold: DS.attr('string'), visibility: DS.attr('string') }); App.AlertReportDefinition = DS.Model.extend({ type: DS.attr('string'), text: DS.attr('string'), value: DS.attr('number') }); App.AlertMetricsSourceDefinition = DS.Model.extend({ propertyList: [], value: DS.attr('string') }); App.AlertMetricsUriDefinition = DS.Model.extend({ http: DS.attr('string'), https: DS.attr('string'), httpsProperty: DS.attr('string'), httpsPropertyValue: DS.attr('string'), connectionTimeout: DS.attr('number') }); App.AlertMetricsAmsDefinition = DS.Model.extend({ value: DS.attr('string'), minimalValue: DS.attr('number'), interval: DS.attr('number') }); App.AlertDefinition.FIXTURES = []; App.AlertReportDefinition.FIXTURES = []; App.AlertMetricsSourceDefinition.FIXTURES = []; App.AlertMetricsUriDefinition.FIXTURES = []; App.AlertMetricsAmsDefinition.FIXTURES = []; App.AlertDefinitionParameter.FIXTURES = []; App.AlertType = DS.Model.extend({ name: DS.attr('string'), displayName: DS.attr('string'), iconPath: DS.attr('string'), description: DS.attr('string'), properties: DS.attr('array') }); App.AlertType.FIXTURES = [{ id: 'PORT', name: 'PORT', icon_path: 'glyphicon glyphicon-log-in', display_name: 'Port', description: Em.I18n.t('alerts.add.wizard.step1.body.port.description') }, { id: 'WEB', name: 'WEB', icon_path: 'glyphicon glyphicon-globe', display_name: 'Web', description: Em.I18n.t('alerts.add.wizard.step1.body.web.description') }, { id: 'METRIC', name: 'METRIC', display_name: 'Metric', icon_path: 'glyphicon glyphicon-flash', description: Em.I18n.t('alerts.add.wizard.step1.body.metric.description') }, { id: 'SCRIPT', name: 'SCRIPT', icon_path: 'glyphicon glyphicon-file', display_name: 'Script', description: Em.I18n.t('alerts.add.wizard.step1.body.script.description') }, { id: 'AGGREGATE', name: 'AGGREGATE', icon_path: 'glyphicon glyphicon-plus', display_name: 'Aggregate', description: Em.I18n.t('alerts.add.wizard.step1.body.aggregate.description') }, { id: 'RAW', name: 'RAW', icon_path: 'glyphicon glyphicon-align-justify', display_name: 'Raw', description: Em.I18n.t('alerts.add.wizard.step1.body.raw.description') }]; }); |