
-- delete from /test/malert_status_cache;

insert into /test/malert_status_cache (
    identifier, severity, lastoccurrence, maintenance, msg, 
    type, agent, firstoccurrence, omni_class, nodealias, 
    alertgroup, node, manager, originalseverity, summary, 
    tags) 
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) 
on conflict 
update firstoccurrence=firstoccurrence, servicenowstate=servicenowstate, emailstatus=emailstatus, tally=tally+1
/**
params(
    "222.129.134.178.1.3.6.1.4.1.2011.5.25.219.2.5.665.25.219.2.5.6.0.{%d,mqli}", 5, 1622249715000, nil, "设备:222.129.134.178电源整体功能恢复!", 
    nil, "huawei mttrapd #x{%d,mqli}", 1622211715023, "300", "222.129.134.178", 
    "huawei_power_func", "222.129.134.178", "MTTrapd Probe", 5, "设备:222.129.134.178电源整体功能恢复!",
    "tag")
loop(10)
**/
;


insert into /test/malert_status_cache (
    identifier, severity, lastoccurrence, maintenance, msg, 
    type, agent, firstoccurrence, omni_class, nodealias, 
    alertgroup, node, manager, originalseverity, summary, 
    tags) 
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) 
on conflict 
update firstoccurrence=firstoccurrence, servicenowstate=servicenowstate, emailstatus=emailstatus, tally=tally+1
/**
params(
    "222.129.134.178.1.3.6.1.4.1.2011.5.25.219.2.5.665.25.219.2.5.6.1.{%d,mqli}", 5, 1622249715000, nil, "设备:222.129.134.178电源整体功能恢复!", 
    1, "huawei mttrapd #1{%d,mqli}", 1622211715023, "300", "222.129.134.178", 
    "huawei_power_func", "222.129.134.178", "MTTrapd Probe", 5, "设备:222.129.134.178电源整体功能恢复!",
    "tag")
loop(10)
**/
;


insert into /test/malert_status_cache (
    identifier, severity, lastoccurrence, maintenance, msg, 
    type, agent, firstoccurrence, omni_class, nodealias, 
    alertgroup, node, manager, originalseverity, summary, 
    tags) 
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) 
on conflict 
update firstoccurrence=firstoccurrence, servicenowstate=servicenowstate, emailstatus=emailstatus, tally=tally+1
/**
params(
    "222.129.134.178.1.3.6.1.4.1.2011.5.25.219.2.5.665.25.219.2.5.6.2.{%d,mqli}", 5, 1622249715000, nil, "设备:222.129.134.178电源整体功能恢复!", 
    2, "huawei mttrapd #2{%d,mqli}", 1622211715023, "300", "222.129.134.178", 
    "huawei_power_func", "222.129.134.178", "MTTrapd Probe", 5, "设备:222.129.134.178电源整体功能恢复!",
    "tag")
loop(10)
**/
;


insert into /test/malert_status_cache (
    identifier, severity, lastoccurrence, maintenance, msg, 
    type, agent, firstoccurrence, omni_class, nodealias, 
    alertgroup, node, manager, originalseverity, summary, 
    tags) 
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) 
on conflict 
update firstoccurrence=firstoccurrence, servicenowstate=servicenowstate, emailstatus=emailstatus, tally=tally+1
/**
params(
    "222.129.134.178.1.3.6.1.4.1.2011.5.25.219.2.5.665.25.219.2.5.6.3.{%d,mqli}", 5, 1622249715000, nil, "设备:222.129.134.178电源整体功能恢复!", 
    3, "huawei mttrapd #3{%d,mqli}", 1622211715023, "300", "222.129.134.178", 
    "huawei_power_func", "222.129.134.178", "MTTrapd Probe", 5, "设备:222.129.134.178电源整体功能恢复!",
    "tag")
loop(10)
**/
;

SELECT
identifier, type, avg(type), vtime, agent, node, tally
FROM /test/malert_status_cache 
-- where agent='huawei mttrapd #48' 
-- and node='222.129.134.178'
-- where type=null
/**
output()
**/
;

