Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
mylxsw committed Jul 10, 2020
1 parent 305ff10 commit f070c2d
Show file tree
Hide file tree
Showing 11 changed files with 1,380 additions and 1,307 deletions.
2,619 changes: 1,320 additions & 1,299 deletions api/static.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dashboard/src/components/TriggerHelp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Trigger {
<li><code>ParseTime(layout string, value string) time.Time</code> 时间字符串转时间对象</li>
<li><code>DailyTimeBetween(startTime, endTime string) bool</code> 判断当前时间是否在 startTime 和 endTime 之间(每天),时间格式为 15:04</li>
<li><code>Messages() []repository.Message</code> 获取分组中所有的 Messages</li>
<li><code>MessagesCount() int64</code> 获取分组中 Messages 数量</li>
<li><code>MessagesMatchRegexCount(regex string) int64</code> 获取匹配指定正则表达式的 message 数量</li>
<li><code>MessagesWithMetaCount(key, value string) int64</code> 获取 meta 匹配指定 key=value 的 message 数量</li>
<li><code>MessagesWithTagsCount(tags string) int64</code> 获取拥有指定 tag 的 message 数量,多个 tag 使用英文逗号分隔</li>
Expand Down
18 changes: 17 additions & 1 deletion dashboard/src/views/Groups.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<template>
<b-row class="mb-5">
<b-col>
<b-card class="mb-2">
<b-card-text>
<b-badge :variant="$route.query.status === undefined ? 'primary':''" class="mr-1" :to="'/'">全部</b-badge>
<b-badge :variant="$route.query.status === status.value ? 'primary': ''" v-for="(status, index) in statuses" :key="index" class="mr-1" :to="'/?status=' + status.value">{{ status.name }}</b-badge>
</b-card-text>
</b-card>
<b-table :items="groups" :fields="fields" :busy="isBusy" show-empty>
<template v-slot:cell(id)="row">
<b-badge class="mr-2" variant="dark">{{ row.item.seq_num }}</b-badge>
Expand All @@ -22,7 +28,7 @@
</b-link>
</template>
<template v-slot:cell(status)="row">
<b-badge v-if="row.item.status === 'collecting'" variant="dark" :title="'预计完成' + formatted(row.item.rule.expect_ready_at) + '完成'" v-b-tooltip.hover>收集中
<b-badge v-if="row.item.status === 'collecting'" variant="dark" :title="'预计' + formatted(row.item.rule.expect_ready_at) + '完成'" v-b-tooltip.hover>收集中
<span v-if="row.item.collect_time_remain > 0">
剩余 <human-time :value="row.item.collect_time_remain"></human-time>
</span>
Expand Down Expand Up @@ -74,8 +80,18 @@
{key: 'status', label: '状态'},
{key: 'operations', label: '操作'}
],
statuses: [
{value: 'collecting', name:'收集中'},
{value: 'pending', name:'准备'},
{value: 'ok', name:'完成'},
{value: 'failed', name:'失败'},
{value: 'canceled', name:'取消'},
]
};
},
watch: {
'$route': 'reload',
},
methods: {
formatted(t) {
return moment(t).format('YYYY-MM-DD HH:mm:ss');
Expand Down
4 changes: 4 additions & 0 deletions dashboard/src/views/RuleEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@
text: 'MessagesWithTagsCount(TAG)',
displayText: 'MessagesWithTagsCount(tags string) int64 | 获取拥有指定 tag 的 message 数量,多个 tag 使用英文逗号分隔'
})
sources.push({
text: 'MessagesCount()',
displayText: 'MessagesCount() int64 | 获取分组中 Messages 数量'
})
sources.push({text: 'TriggeredTimesInPeriod(PERIOD_IN_MINUTES, TRIGGER_STATUS)', displayText: 'TriggeredTimesInPeriod(periodInMinutes int, triggerStatus string) int64 当前规则在指定时间范围内,状态为 triggerStatus 的触发次数'})
sources.push({text: 'LastTriggeredGroup(TRIGGER_STATUS)', displayText: 'LastTriggeredGroup(triggerStatus string) repository.MessageGroup 最后一次触发该规则的状态为 triggerStatus 的分组'})
Expand Down
4 changes: 3 additions & 1 deletion dashboard/src/views/Rules.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@
<strong> Loading...</strong>
</template>
<template v-slot:cell(operations)="row">
<b-button-group>
<b-button-group class="mr-2">
<b-button size="sm" variant="success" :to="{path:'/', query:{rule_id: row.item.id}}">报警</b-button>
<b-button size="sm" variant="warning" :to="{path:'/rules/add', query: {copy_from: row.item.id}}" target="_blank">复制</b-button>
</b-button-group>
<b-button-group>
<b-button size="sm" variant="info" :to="{path:'/rules/' + row.item.id + '/edit'}">编辑</b-button>
<b-button size="sm" variant="danger" @click="delete_rule(row.index, row.item.id)">删除</b-button>
</b-button-group>
Expand Down
5 changes: 3 additions & 2 deletions dashboard/src/views/Templates.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@
<strong> Loading...</strong>
</template>
<template v-slot:cell(operations)="row">
<b-button-group>
<b-button-group class="mr-2">
<b-button size="sm" @click="row.toggleDetails">
{{ row.detailsShowing ? '隐藏' : '显示' }}详情
</b-button>

</b-button-group>
<b-button-group>
<b-button v-if="!row.item.predefined" size="sm" variant="info" :to="{path:'/templates/' + row.item.id + '/edit'}">编辑</b-button>
<b-button v-if="!row.item.predefined" size="sm" variant="danger" @click="delete_template(row.index, row.item.id)">删除</b-button>
<b-button v-if="row.item.predefined" size="sm" disabled>预置</b-button>
Expand Down
5 changes: 4 additions & 1 deletion dashboard/src/views/Users.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@
<strong> Loading...</strong>
</template>
<template v-slot:cell(operations)="row">
<b-button-group>
<b-button-group class="mr-2">
<b-button size="sm" variant="success" :to="{path:'/', query:{user_id: row.item.id}}">报警</b-button>
<b-button size="sm" variant="dark" :to="{path:'/rules', query:{user_id: row.item.id}}">规则</b-button>

</b-button-group>
<b-button-group>
<b-button size="sm" variant="info" :to="{path:'/users/' + row.item.id + '/edit'}">编辑</b-button>
<b-button size="sm" variant="danger" @click="delete_user(row.index, row.item.id)">删除</b-button>
</b-button-group>
Expand Down
12 changes: 12 additions & 0 deletions internal/matcher/trigger_matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ func (tc *TriggerContext) Messages() []repository.Message {
return tc.messages
}

// MessagesCount return the count in group
func (tc *TriggerContext) MessagesCount() int64 {
var count int64 = 0
tc.cc.MustResolve(func(msgRepo repository.MessageRepo) {
count, _ = msgRepo.Count(bson.M{
"group_ids": tc.Group.ID,
})
})

return count
}

// MessagesMatchRegexCount get the count for messages matched regex
func (tc *TriggerContext) MessagesMatchRegexCount(regex string) int64 {
var count int64 = 0
Expand Down
4 changes: 2 additions & 2 deletions internal/repository/impl/dingding_robot.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (u DingdingRobotRepo) Get(id primitive.ObjectID) (robot repository.Dingding

func (u DingdingRobotRepo) Find(filter bson.M) (robots []repository.DingdingRobot, err error) {
robots = make([]repository.DingdingRobot, 0)
cur, err := u.col.Find(context.TODO(), filter)
cur, err := u.col.Find(context.TODO(), filter, options.Find().SetSort(bson.M{"name": -1}))
if err != nil {
return
}
Expand All @@ -61,7 +61,7 @@ func (u DingdingRobotRepo) Find(filter bson.M) (robots []repository.DingdingRobo

func (u DingdingRobotRepo) Paginate(filter bson.M, offset, limit int64) (robots []repository.DingdingRobot, next int64, err error) {
robots = make([]repository.DingdingRobot, 0)
cur, err := u.col.Find(context.TODO(), filter, options.Find().SetSkip(offset).SetLimit(limit).SetSort(bson.M{"created_at": -1}))
cur, err := u.col.Find(context.TODO(), filter, options.Find().SetSkip(offset).SetLimit(limit).SetSort(bson.M{"name": -1}))
if err != nil {
return
}
Expand Down
9 changes: 8 additions & 1 deletion internal/repository/impl/message_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,14 @@ func (m MessageGroupRepo) Find(filter bson.M) (grps []repository.MessageGroup, e

func (m MessageGroupRepo) Paginate(filter bson.M, offset, limit int64) (grps []repository.MessageGroup, next int64, err error) {
grps = make([]repository.MessageGroup, 0)
cur, err := m.col.Find(context.TODO(), filter, options.Find().SetSkip(offset).SetLimit(limit).SetSort(bson.M{"created_at": -1}))
cur, err := m.col.Find(
context.TODO(),
filter,
options.Find().
SetSkip(offset).
SetLimit(limit).
SetSort(bson.M{"updated_at": -1}),
)
if err != nil {
return
}
Expand Down
6 changes: 6 additions & 0 deletions migrate/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ var predefinedTemplates = []repository.Template{
Content: `DailyTimeBetween("22:00", "9:00")`,
Type: repository.TemplateTypeTriggerRule,
},
{
Name: "判断分组中 Messages 数量是否大于某个值",
Description: "当前分组中有超过 10 条 Messages",
Content: `MessagesCount() > 10`,
Type: repository.TemplateTypeTriggerRule,
},
{
Name: "展示概要信息",
Description: "展示分组的概要信息",
Expand Down

0 comments on commit f070c2d

Please sign in to comment.