| 5519 |
amar.kumar |
1 |
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
2 |
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
|
3 |
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
|
4 |
|
|
|
5 |
<mapper namespace="in.shop2020.alert.persistence.EntityMapper">
|
|
|
6 |
<resultMap type="monitored_entity" id="monitored_entityResult">
|
|
|
7 |
<id property="id" column="id"/>
|
|
|
8 |
</resultMap>
|
|
|
9 |
|
|
|
10 |
<select id="isEntityMonitorable" parameterType="int" resultType="boolean">
|
|
|
11 |
SELECT isActive
|
|
|
12 |
FROM entity_monitoring_status
|
|
|
13 |
<where>
|
|
|
14 |
entityType = #{entityType}
|
|
|
15 |
</where>
|
|
|
16 |
</select>
|
|
|
17 |
|
|
|
18 |
<insert id="insertEntity" parameterType="monitored_entity" useGeneratedKeys="true" keyProperty="id">
|
|
|
19 |
INSERT INTO monitored_entity
|
|
|
20 |
(entityType, eventType, entityIdentifier, warnExpiryTime, criticalExpiryTime, entityProperties, entityProcessedState)
|
|
|
21 |
VALUES
|
|
|
22 |
(#{entityType}, #{eventType}, #{entityIdentifier}, #{warnExpiryTime}, #{criticalExpiryTime}, #{entityProperties}, 1)
|
|
|
23 |
</insert>
|
|
|
24 |
|
|
|
25 |
<update id="updateEntity" parameterType="monitored_entity">
|
|
|
26 |
UPDATE monitored_entity
|
|
|
27 |
SET eventType=#{eventType}, warnExpiryTime=#{warnExpiryTime},
|
|
|
28 |
criticalExpiryTime=#{criticalExpiryTime},
|
|
|
29 |
entityProperties=#{entityProperties}
|
|
|
30 |
<where>
|
|
|
31 |
id = #{id}
|
|
|
32 |
</where>
|
|
|
33 |
</update>
|
|
|
34 |
|
|
|
35 |
<!-- select id="isEntityMonitorable" parameterType="int" resultType="int">
|
|
|
36 |
SELECT ISNULL((SELECT 1 FROM entity_monitoring_status WHERE entityType = entityType AND isActive = true), 0)
|
|
|
37 |
</select-->
|
|
|
38 |
|
|
|
39 |
<select id="getEntity" parameterType="map" resultType="monitored_entity">
|
|
|
40 |
SELECT *
|
|
|
41 |
FROM monitored_entity
|
|
|
42 |
<where>
|
|
|
43 |
entityType = #{entityType}
|
|
|
44 |
AND entityIdentifier = #{entityIdentifier}
|
|
|
45 |
</where>
|
|
|
46 |
</select>
|
|
|
47 |
|
| 5536 |
amar.kumar |
48 |
<select id="getEntityMonitoringStatus" parameterType="int" resultType="entity_monitoring_status">
|
|
|
49 |
SELECT *
|
|
|
50 |
FROM entity_monitoring_status
|
|
|
51 |
<where>
|
|
|
52 |
entityType = #{entityType}
|
|
|
53 |
</where>
|
|
|
54 |
</select>
|
|
|
55 |
|
| 5519 |
amar.kumar |
56 |
<insert id="insertAlertedEntity" parameterType="map" useGeneratedKeys="true" keyProperty="id">
|
|
|
57 |
INSERT INTO alerted_entity
|
|
|
58 |
(entityType, eventType, entityIdentifier, lastAlertedTime, entityProperties, entityProcessedState)
|
|
|
59 |
VALUES
|
|
|
60 |
(#{entityType}, #{eventType}, #{entityIdentifier}, #{lastAlertedTime}, #{entityProperties}, #{entityProcessedState})
|
|
|
61 |
</insert>
|
|
|
62 |
|
|
|
63 |
<delete id="removeMonitoredEntity" parameterType="map">
|
|
|
64 |
DELETE FROM monitored_entity
|
|
|
65 |
<where>
|
|
|
66 |
entityType = #{entityType}
|
|
|
67 |
AND entityIdentifier = #{entityIdentifier}
|
|
|
68 |
</where>
|
|
|
69 |
</delete>
|
|
|
70 |
|
|
|
71 |
<select id="getEntitiesToBeAlerted" resultType="monitored_entity">
|
|
|
72 |
SELECT *
|
|
|
73 |
FROM monitored_entity
|
|
|
74 |
<where>
|
|
|
75 |
(warnExpiryTime <= NOW()
|
|
|
76 |
AND entityProcessedState < 1)
|
|
|
77 |
OR (criticalExpiryTime <= NOW()
|
|
|
78 |
AND entityProcessedState < 2)
|
|
|
79 |
</where>
|
|
|
80 |
</select>
|
|
|
81 |
|
|
|
82 |
<update id="updateEntityProcessedState" parameterType="map">
|
|
|
83 |
UPDATE monitored_entity
|
|
|
84 |
SET entityProcessedState=#{state}
|
|
|
85 |
<where>
|
|
|
86 |
id = #{id}
|
|
|
87 |
</where>
|
|
|
88 |
</update>
|
|
|
89 |
|
|
|
90 |
<select id="getEntities" parameterType="searchFilter" resultType="monitored_entity">
|
|
|
91 |
SELECT * from monitored_entity
|
|
|
92 |
<where>
|
|
|
93 |
<if test="entityType != 0">
|
|
|
94 |
AND entityType = #{entityType}
|
|
|
95 |
</if>
|
|
|
96 |
<if test="eventType != null">
|
|
|
97 |
AND eventType = #{eventType}
|
|
|
98 |
</if>
|
|
|
99 |
<if test="entityIdentifier != null">
|
|
|
100 |
AND entityIdentifier = #{entityIdentifier}
|
|
|
101 |
</if>
|
|
|
102 |
<if test="entityProcessedState != null">
|
|
|
103 |
AND entityProcessedState = #{entityProcessedState}
|
|
|
104 |
</if>
|
|
|
105 |
</where>
|
|
|
106 |
</select>
|
|
|
107 |
|
|
|
108 |
<select id="getAlertedEntities" parameterType="searchFilter" resultType="alerted_entity">
|
|
|
109 |
SELECT * from alerted_entity
|
|
|
110 |
<where>
|
|
|
111 |
<if test="entityType != null">
|
|
|
112 |
AND entityType = #{entityType}
|
|
|
113 |
</if>
|
|
|
114 |
<if test="eventType != null">
|
|
|
115 |
AND eventType = #{eventType}
|
|
|
116 |
</if>
|
|
|
117 |
<if test="entityIdentifier != null">
|
|
|
118 |
AND entityIdentifier = #{entityIdentifier}
|
|
|
119 |
</if>
|
|
|
120 |
<if test="entityProcessedState != null">
|
|
|
121 |
AND entityProcessedState = #{entityProcessedState}
|
|
|
122 |
</if>
|
|
|
123 |
</where>
|
|
|
124 |
</select>
|
|
|
125 |
|
|
|
126 |
<select id="getAlertMapper" parameterType="map" resultType="alert_mapper">
|
|
|
127 |
SELECT *
|
|
|
128 |
FROM alert_mapper
|
|
|
129 |
<where>
|
|
|
130 |
entityType = #{entityType}
|
|
|
131 |
AND eventType = #{eventType}
|
|
|
132 |
</where>
|
|
|
133 |
LIMIT 1
|
|
|
134 |
</select>
|
|
|
135 |
|
|
|
136 |
<update id="activateEntityMonitoring" parameterType="map">
|
|
|
137 |
UPDATE entity_monitoring_status
|
|
|
138 |
SET isActive = true
|
|
|
139 |
AND defaultAlertGroup = #{userIds}
|
|
|
140 |
<where>
|
|
|
141 |
entityType = #{entityType}
|
|
|
142 |
</where>
|
|
|
143 |
</update>
|
|
|
144 |
|
|
|
145 |
<update id="deActivateEntityMonitoring" parameterType="map">
|
|
|
146 |
UPDATE entity_monitoring_status
|
|
|
147 |
SET isActive = 0
|
|
|
148 |
<where>
|
|
|
149 |
entityType = #{entityType}
|
|
|
150 |
</where>
|
|
|
151 |
</update>
|
|
|
152 |
|
|
|
153 |
<insert id="registerEventType" parameterType="alert_mapper">
|
|
|
154 |
INSERT INTO alert_mapper
|
|
|
155 |
(entityType, eventType, eventDescription, userIds, alertType)
|
|
|
156 |
VALUES
|
|
|
157 |
(#{entityType}, #{eventType}, #{eventDescription}, #{userIds}, #{alertType})
|
|
|
158 |
</insert>
|
|
|
159 |
|
|
|
160 |
</mapper>
|