fix(xo-server-perf-alert): make message compatible with XenCenter (#5004)

This commit is contained in:
Nicolas Raynaud 2020-05-18 14:56:11 +02:00 committed by GitHub
parent 3388e5e8a4
commit 6cf211a9ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 18 deletions

View File

@ -23,6 +23,7 @@
- Fix default filters not being set in all tables (PR [#4994](https://github.com/vatesfr/xen-orchestra/pull/4994)) - Fix default filters not being set in all tables (PR [#4994](https://github.com/vatesfr/xen-orchestra/pull/4994))
- [SDN Controller] Broken encrypted tunnels after host reboot [#4996](https://github.com/vatesfr/xen-orchestra/pull/4996) - [SDN Controller] Broken encrypted tunnels after host reboot [#4996](https://github.com/vatesfr/xen-orchestra/pull/4996)
- Don't log server's credentials in case of `SESSION_AUTHENTICATION_FAILED` error (PR [#4995](https://github.com/vatesfr/xen-orchestra/pull/4995)) - Don't log server's credentials in case of `SESSION_AUTHENTICATION_FAILED` error (PR [#4995](https://github.com/vatesfr/xen-orchestra/pull/4995))
- [Plugin/perf-alert] Fix compatibility of the alert messages with XenCenter (PR [#5004](https://github.com/vatesfr/xen-orchestra/pull/5004))
### Released packages ### Released packages
@ -41,6 +42,7 @@
> >
> In case of conflict, the highest (lowest in previous list) `$version` wins. > In case of conflict, the highest (lowest in previous list) `$version` wins.
- xo-server-perf-alert patch
- xen-api patch - xen-api patch
- xo-server-auth-ldap minor - xo-server-auth-ldap minor
- xo-server-sdn-controller patch - xo-server-sdn-controller patch

View File

@ -3,6 +3,12 @@ import { createSchedule } from '@xen-orchestra/cron'
import { forOwn, map, mean } from 'lodash' import { forOwn, map, mean } from 'lodash'
import { utcParse } from 'd3-time-format' import { utcParse } from 'd3-time-format'
const XAPI_TO_XENCENTER = {
cpuUsage: 'cpu_usage',
memoryUsage: 'mem_usage',
storageUsage: 'physical_utilisation',
}
const COMPARATOR_FN = { const COMPARATOR_FN = {
'>': (a, b) => a > b, '>': (a, b) => a > b,
'<': (a, b) => a < b, '<': (a, b) => a < b,
@ -33,6 +39,7 @@ const VM_FUNCTIONS = {
getDisplayableValue, getDisplayableValue,
shouldAlarm: () => shouldAlarm: () =>
COMPARATOR_FN[comparator](getDisplayableValue(), threshold), COMPARATOR_FN[comparator](getDisplayableValue(), threshold),
threshold,
} }
}, },
}, },
@ -58,6 +65,7 @@ const VM_FUNCTIONS = {
getDisplayableValue, getDisplayableValue,
shouldAlarm: () => shouldAlarm: () =>
COMPARATOR_FN[comparator](getDisplayableValue(), threshold), COMPARATOR_FN[comparator](getDisplayableValue(), threshold),
threshold,
} }
}, },
}, },
@ -88,6 +96,7 @@ const HOST_FUNCTIONS = {
getDisplayableValue, getDisplayableValue,
shouldAlarm: () => shouldAlarm: () =>
COMPARATOR_FN[comparator](getDisplayableValue(), threshold), COMPARATOR_FN[comparator](getDisplayableValue(), threshold),
threshold,
} }
}, },
}, },
@ -113,6 +122,7 @@ const HOST_FUNCTIONS = {
getDisplayableValue, getDisplayableValue,
shouldAlarm: () => shouldAlarm: () =>
COMPARATOR_FN[comparator](getDisplayableValue(), threshold), COMPARATOR_FN[comparator](getDisplayableValue(), threshold),
threshold,
} }
}, },
}, },
@ -131,6 +141,7 @@ const SR_FUNCTIONS = {
getDisplayableValue, getDisplayableValue,
shouldAlarm: () => shouldAlarm: () =>
COMPARATOR_FN[comparator](getDisplayableValue(), threshold), COMPARATOR_FN[comparator](getDisplayableValue(), threshold),
threshold,
} }
}, },
}, },
@ -487,6 +498,8 @@ ${monitorBodies.join('\n')}`
data, data,
value: data.getDisplayableValue(), value: data.getDisplayableValue(),
shouldAlarm: data.shouldAlarm(), shouldAlarm: data.shouldAlarm(),
threshold: data.threshold,
observationPeriod,
}) })
} }
} else { } else {
@ -499,6 +512,8 @@ ${monitorBodies.join('\n')}`
Object.assign(result, { Object.assign(result, {
value: data.getDisplayableValue(), value: data.getDisplayableValue(),
shouldAlarm: data.shouldAlarm(), shouldAlarm: data.shouldAlarm(),
threshold: data.threshold,
observationPeriod,
}) })
} }
@ -596,23 +611,23 @@ ${entry.listItem}`
continue continue
} }
const raiseAlarm = alarmId => { const raiseAlarm = _alarmId => {
// sample XenCenter message: // sample XenCenter message (linebreaks are meaningful):
// value: 1.242087 config: <variable> <name value="mem_usage"/> </variable> // value: 1.242087\n config: <variable>\n <name value="mem_usage"/>\n<alarm_trigger_level value="0.5"/>\n <alarm_trigger_period value ="60"/>\n</variable>
this._xo this._xo.getXapi(entry.object.uuid).call(
.getXapi(entry.object.uuid) 'message.create',
.call( 'ALARM',
'message.create', 3,
'ALARM', entry.object.$type,
3, entry.object.uuid,
entry.object.$type, `value: ${(entry.value / 100).toFixed(1)}
entry.object.uuid, config:
`value: ${entry.value.toFixed( <variable>
1 <name value="${XAPI_TO_XENCENTER[monitor.variableName]}"/>
)} config: <variable> <name value="${ <alarm_trigger_level value="${entry.threshold / 100}"/>
monitor.variableName <alarm_trigger_period value ="${entry.observationPeriod}"/>
}"/> </variable>` </variable>`
) )
this._sendAlertEmail( this._sendAlertEmail(
'', '',
` `
@ -623,7 +638,7 @@ ${entry.listItem}
) )
} }
const lowerAlarm = alarmId => { const lowerAlarm = _alarmId => {
this._sendAlertEmail( this._sendAlertEmail(
'END OF ALERT', 'END OF ALERT',
` `