diff options
Diffstat (limited to 'sdnr/wt/odlux/apps/faultApp/src/services')
-rw-r--r-- | sdnr/wt/odlux/apps/faultApp/src/services/faultStatusService.ts | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/sdnr/wt/odlux/apps/faultApp/src/services/faultStatusService.ts b/sdnr/wt/odlux/apps/faultApp/src/services/faultStatusService.ts new file mode 100644 index 000000000..ad0d394ce --- /dev/null +++ b/sdnr/wt/odlux/apps/faultApp/src/services/faultStatusService.ts @@ -0,0 +1,22 @@ +import { requestRest } from "../../../../framework/src/services/restService"; +import { Result } from "../../../../framework/src/models/elasticSearch"; + +export const getFaultStateFromDatabase = async (): Promise < { [key: string]: number } | null > => { + const path = 'database/sdnevents/faultcurrent/_search'; + const query = { + "size": 0, + "aggregations": { + "severity": { + "terms": { + "field": "faultCurrent.severity" + } + } + } + }; + + const result = await requestRest<Result<{ severity: { buckets: { key: string, doc_count: number }[] } }>>(path, { method: "POST", body: JSON.stringify(query) }); + return result && result.aggregations && result.aggregations["severity"].buckets.reduce<{ [key: string]: number }>((acc, cur) => { + acc[cur.key] = cur.doc_count; + return acc; + }, {}) || null; +}
\ No newline at end of file |