alert_instance.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. var dateUtils = require('utils/date');
  20. App.AlertInstance = DS.Model.extend({
  21. id: DS.attr('number'),
  22. label: DS.attr('string'),
  23. definitionName: DS.attr('string'),
  24. definitionId: DS.attr('number'),
  25. service: DS.belongsTo('App.Service'),
  26. componentName: DS.attr('string'),
  27. host: DS.belongsTo('App.Host'),
  28. scope: DS.attr('string'),
  29. originalTimestamp: DS.attr('number'),
  30. latestTimestamp: DS.attr('number'),
  31. maintenanceState: DS.attr('string'),
  32. instance: DS.attr('string'),
  33. state: DS.attr('string'),
  34. text: DS.attr('string'),
  35. notification: DS.hasMany('App.AlertNotification'),
  36. formattedNotifications: function () {
  37. return this.get('notification').mapProperty('name').join(', ');
  38. }.property('notification'),
  39. /**
  40. * Status icon markup
  41. * @type {App.AlertDefinition[]}
  42. */
  43. status: function () {
  44. var typeIcons = this.get('typeIcons');
  45. var state = this.get('state');
  46. return '<span class="' + typeIcons[state] + ' alert-state-' + state + '"></span>';
  47. }.property('state'),
  48. /**
  49. * Formatted timestamp for latest instance triggering
  50. * @type {string}
  51. */
  52. lastTriggered: function() {
  53. return dateUtils.dateFormat(this.get('latestTimestamp'));
  54. }.property('latestTimestamp'),
  55. /**
  56. * List of css-classes for alert instance status
  57. * @type {object}
  58. */
  59. typeIcons: {
  60. 'OK': 'icon-ok-sign',
  61. 'WARNING': 'icon-warning-sign',
  62. 'CRITICAL': 'icon-remove',
  63. 'DISABLED': 'icon-off',
  64. 'UNKNOWN': 'icon-question-sign'
  65. }
  66. });
  67. App.AlertInstance.FIXTURES = [];