mirror of
https://github.com/hansjone/netxops.git
synced 2026-10-09 10:43:18 +08:00
Fix key-alarm IM delivery blocked by DSH session sink.
Run session and WhatsApp/IM sinks in parallel so a failing or slow sticky session no longer skips proactive IM delivery (0.1.34). Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
3a731389f0
commit
da08c38949
5 changed files with 157 additions and 15 deletions
67
test/alarm-dispatch.test.mjs
Normal file
67
test/alarm-dispatch.test.mjs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
import assert from 'node:assert/strict'
|
||||
import { test } from 'node:test'
|
||||
|
||||
import { dispatchAlarmToSinks } from '../src/netx/alarm-dispatch.ts'
|
||||
|
||||
test('dispatchAlarmToSinks still delivers IM when DSH session rejects', async () => {
|
||||
let imCalls = 0
|
||||
const warnings = []
|
||||
const ctx = {
|
||||
logger: {
|
||||
warn: (...args) => { warnings.push(args.map(String).join(' ')) },
|
||||
info() {},
|
||||
},
|
||||
}
|
||||
const results = await dispatchAlarmToSinks(
|
||||
ctx,
|
||||
{
|
||||
action: 'inserted',
|
||||
rule_label: 'Power Down',
|
||||
alarm_key: 'k1',
|
||||
ne: { host_name: 'PE1' },
|
||||
},
|
||||
{
|
||||
deliverDsh: true,
|
||||
deliverIm: true,
|
||||
imTargets: [{ botId: 'bot', targetId: 'tgt' }],
|
||||
lang: 'zh',
|
||||
},
|
||||
{
|
||||
toSession: async () => {
|
||||
throw new Error('sticky session exploded')
|
||||
},
|
||||
toIm: async () => {
|
||||
imCalls += 1
|
||||
},
|
||||
},
|
||||
)
|
||||
assert.equal(imCalls, 1)
|
||||
assert.equal(results.length, 2)
|
||||
assert.equal(results[0].status, 'rejected')
|
||||
assert.equal(results[1].status, 'fulfilled')
|
||||
assert.ok(warnings.some((line) => line.includes('sink failed')))
|
||||
})
|
||||
|
||||
test('dispatchAlarmToSinks skips session job when deliverDsh is false', async () => {
|
||||
let sessionCalls = 0
|
||||
let imCalls = 0
|
||||
const ctx = { logger: { warn() {}, info() {} } }
|
||||
const results = await dispatchAlarmToSinks(
|
||||
ctx,
|
||||
{ action: 'inserted', alarm_key: 'k1' },
|
||||
{
|
||||
deliverDsh: false,
|
||||
deliverIm: true,
|
||||
imTargets: [{ botId: 'bot', targetId: 'tgt' }],
|
||||
lang: 'zh',
|
||||
},
|
||||
{
|
||||
toSession: async () => { sessionCalls += 1 },
|
||||
toIm: async () => { imCalls += 1 },
|
||||
},
|
||||
)
|
||||
assert.equal(sessionCalls, 0)
|
||||
assert.equal(imCalls, 1)
|
||||
assert.equal(results.length, 1)
|
||||
assert.equal(results[0].status, 'fulfilled')
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue