1
1
<template >
2
- <div class =" plugin" >
3
- <section id =" alerts" >
2
+ <div class =" plugin" >
3
+ <section id =" alerts" >
4
4
<span class =" title" v-if =" hasAlerts" >
5
5
Warning or critical alerts (last {{ countAlerts }} entries)
6
6
</span >
7
- <span class =" title" v-else >No warning or critical alert detected</span >
8
- </section >
9
- <section id =" alert" >
10
- <div class =" table" >
11
- <div class =" table-row" v-for =" (alert, alertId) in alerts" :key =" alertId" >
12
- <div class =" table-cell text-left" >
13
- {{ formatDate(alert.begin) }}
14
- {{ alert.tz }}
15
- ({{ alert.ongoing ? 'ongoing' : alert.duration }}) -
16
- <span v-show =" !alert.ongoing" > {{ alert.state }} on </span >
17
- <span :class =" alert.state.toLowerCase()" >
7
+ <span class =" title" v-else >No warning or critical alert detected</span >
8
+ </section >
9
+ <section id =" alert" >
10
+ <div class =" table" >
11
+ <div class =" table-row" v-for =" (alert, alertId) in alerts" :key =" alertId" >
12
+ <div class =" table-cell text-left" >
13
+ {{ formatDate(alert.begin) }}
14
+ ({{ alert.ongoing ? 'ongoing' : alert.duration }}) -
15
+ <span v-show =" !alert.ongoing" > {{ alert.state }} on </span >
16
+ <span :class =" alert.state.toLowerCase()" >
18
17
{{ alert.type }}
19
- </span >
20
- ({{ $filters.number(alert.max, 1) }})
21
- {{ alert.top }}
22
- </div >
23
- </div >
24
- </div >
25
- </section >
26
- </div >
18
+ </span >
19
+ ({{ $filters.number(alert.max, 1) }})
20
+ {{ alert.top }}
21
+ </div >
22
+ </div >
23
+ </div >
24
+ </section >
25
+ </div >
27
26
</template >
28
27
29
28
<script >
30
- import { padStart } from ' lodash' ;
31
- import { GlancesFavico } from ' ../services.js' ;
29
+ import {padStart } from ' lodash' ;
30
+ import {GlancesFavico } from ' ../services.js' ;
32
31
33
32
export default {
34
- props: {
35
- data: {
36
- type: Object
37
- }
33
+ props: {
34
+ data: {
35
+ type: Object
36
+ }
37
+ },
38
+ computed: {
39
+ stats () {
40
+ return this .data .stats [' alert' ];
38
41
},
39
- computed: {
40
- stats () {
41
- return this .data .stats [' alert' ];
42
- },
43
- alerts () {
44
- return (this .stats || []).map ((alertalertStats ) => {
45
- const alert = {};
46
- var tzoffset = new Date ().getTimezoneOffset ();
47
- alert .state = alertalertStats .state ;
48
- alert .type = alertalertStats .type ;
49
- alert .begin = alertalertStats .begin * 1000 - tzoffset * 60 * 1000 ;
50
- alert .end = alertalertStats .end * 1000 - tzoffset * 60 * 1000 ;
51
- alert .ongoing = alertalertStats .end == - 1 ;
52
- alert .min = alertalertStats .min ;
53
- alert .avg = alertalertStats .avg ;
54
- alert .max = alertalertStats .max ;
55
- alert .top = alertalertStats .top .join (' , ' );
56
-
57
- if (! alert .ongoing ) {
58
- const duration = alert .end - alert .begin ;
59
- const seconds = parseInt ((duration / 1000 ) % 60 ),
60
- minutes = parseInt ((duration / (1000 * 60 )) % 60 ),
61
- hours = parseInt ((duration / (1000 * 60 * 60 )) % 24 );
42
+ alerts () {
43
+ return (this .stats || []).map ((alertStats ) => {
44
+ const alert = {};
45
+ alert .state = alertStats .state ;
46
+ alert .type = alertStats .type ;
47
+ alert .begin = alertStats .begin * 1000 ;
48
+ alert .end = alertStats .end * 1000 ;
49
+ alert .ongoing = alertStats .end == - 1 ;
50
+ alert .min = alertStats .min ;
51
+ alert .avg = alertStats .avg ;
52
+ alert .max = alertStats .max ;
53
+ alert .top = alertStats .top .join (' , ' );
62
54
63
- alert .duration =
64
- padStart (hours, 2 , ' 0' ) +
65
- ' :' +
66
- padStart (minutes, 2 , ' 0' ) +
67
- ' :' +
68
- padStart (seconds, 2 , ' 0' );
69
- }
55
+ if (! alert .ongoing ) {
56
+ const duration = alert .end - alert .begin ;
57
+ const seconds = parseInt ((duration / 1000 ) % 60 ),
58
+ minutes = parseInt ((duration / (1000 * 60 )) % 60 ),
59
+ hours = parseInt ((duration / (1000 * 60 * 60 )) % 24 );
70
60
71
- return alert;
72
- });
73
- },
74
- hasAlerts () {
75
- return this .countAlerts > 0 ;
76
- },
77
- countAlerts () {
78
- return this .alerts .length ;
79
- },
80
- hasOngoingAlerts () {
81
- return this .countOngoingAlerts > 0 ;
82
- },
83
- countOngoingAlerts () {
84
- return this .alerts .filter (({ ongoing }) => ongoing).length ;
61
+ alert .duration = padStart (hours, 2 , ' 0' ) +
62
+ ' :' + padStart (minutes, 2 , ' 0' ) +
63
+ ' :' + padStart (seconds, 2 , ' 0' );
85
64
}
65
+
66
+ return alert;
67
+ });
86
68
},
87
- watch: {
88
- countOngoingAlerts () {
89
- if (this .countOngoingAlerts ) {
90
- GlancesFavico .badge (this .countOngoingAlerts );
91
- } else {
92
- GlancesFavico .reset ();
93
- }
94
- }
69
+ hasAlerts () {
70
+ return this .countAlerts > 0 ;
95
71
},
96
- methods: {
97
- formatDate (date ) {
98
- return new Date (date).toLocaleString ();
99
- }
72
+ countAlerts () {
73
+ return this .alerts .length ;
74
+ },
75
+ hasOngoingAlerts () {
76
+ return this .countOngoingAlerts > 0 ;
77
+ },
78
+ countOngoingAlerts () {
79
+ return this .alerts .filter (({ongoing}) => ongoing).length ;
80
+ }
81
+ },
82
+ watch: {
83
+ countOngoingAlerts () {
84
+ if (this .countOngoingAlerts ) {
85
+ GlancesFavico .badge (this .countOngoingAlerts );
86
+ } else {
87
+ GlancesFavico .reset ();
88
+ }
89
+ }
90
+ },
91
+ methods: {
92
+ formatDate (timestamp ) {
93
+ const tzOffset = new Date ().getTimezoneOffset ();
94
+ const hours = Math .trunc (Math .abs (tzOffset) / 60 );
95
+ const minutes = Math .abs (tzOffset % 60 );
96
+
97
+ let tzString = tzOffset <= 0 ? ' +' : ' -' ;
98
+ tzString += String (hours).padStart (2 , ' 0' ) + String (minutes).padStart (2 , ' 0' );
99
+
100
+ const date = new Date (timestamp);
101
+ return String (date .getFullYear ()) +
102
+ ' -' + String (date .getMonth ()).padStart (2 , ' 0' ) +
103
+ ' -' + String (date .getDate ()).padStart (2 , ' 0' ) +
104
+ ' ' + String (date .getHours ()).padStart (2 , ' 0' ) +
105
+ ' :' + String (date .getMinutes ()).padStart (2 , ' 0' ) +
106
+ ' :' + String (date .getSeconds ()).padStart (2 , ' 0' ) +
107
+ ' (' + tzString + ' )' ;
100
108
}
109
+ }
101
110
};
102
111
</script >
0 commit comments