├── .github ├── ISSUE_TEMPLATE │ └── bug-report.yaml ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── deploy.yaml │ └── main.yaml ├── .gitignore ├── .golangci.yaml ├── Dockerfile ├── DockerfileBuild ├── DockerfileDeploy ├── LICENSE ├── Makefile ├── README-zh.md ├── README.md ├── api ├── .gitignore ├── admin │ ├── alarm │ │ ├── alarm.proto │ │ ├── send.proto │ │ └── time_engine_rule.proto │ ├── authorization │ │ └── authorization.proto │ ├── datasource │ │ ├── datasource.proto │ │ └── metric.proto │ ├── dict │ │ └── dict.proto │ ├── file │ │ └── file.proto │ ├── history │ │ └── alarm.proto │ ├── hook │ │ └── hook.proto │ ├── invite │ │ └── invite.proto │ ├── menu │ │ └── menu.proto │ ├── model.proto │ ├── realtime │ │ ├── alarm.proto │ │ ├── alarm_page_self.proto │ │ ├── dashboard.proto │ │ └── statistics.proto │ ├── resource │ │ └── resource.proto │ ├── strategy │ │ ├── strategy.proto │ │ └── template.proto │ ├── subscriber │ │ └── subscriber.proto │ ├── system │ │ └── system.proto │ ├── team │ │ ├── department.proto │ │ ├── role.proto │ │ └── team.proto │ ├── template │ │ └── send_template.proto │ └── user │ │ ├── message.proto │ │ └── user.proto ├── alert.proto ├── datasource.proto ├── enum.proto ├── global.proto ├── health.proto ├── helloworld │ └── v1 │ │ ├── error_reason.proto │ │ └── greeter.proto ├── houyi │ ├── alert │ │ └── alert.proto │ ├── metadata │ │ └── metric.proto │ └── strategy │ │ └── strategy.proto ├── metadata.proto ├── rabbit │ ├── hook │ │ └── hook.proto │ └── push │ │ └── config.proto ├── server.proto ├── strategy.proto └── v1 │ └── hello.proto ├── build_images.sh ├── cmd ├── config │ └── modeltype.go ├── option │ ├── gen_model.go │ ├── root.go │ ├── server.go │ └── version.go ├── server.go └── server │ ├── demo │ ├── Makefile │ ├── configs │ │ └── config.yaml │ ├── demo │ │ └── cmd.go │ ├── internal │ │ ├── biz │ │ │ ├── README.md │ │ │ ├── biz.go │ │ │ ├── bo │ │ │ │ └── select.go │ │ │ ├── greeter.go │ │ │ ├── hello.go │ │ │ └── repository │ │ │ │ ├── cache_repo.go │ │ │ │ └── hello.go │ │ ├── data │ │ │ ├── README.md │ │ │ ├── data.go │ │ │ ├── greeter.go │ │ │ └── repoimpl │ │ │ │ ├── cache_repo_impl.go │ │ │ │ ├── hello.go │ │ │ │ └── repo_impl.go │ │ ├── democonf │ │ │ ├── .gitignore │ │ │ └── conf.proto │ │ ├── server │ │ │ ├── grpc.go │ │ │ ├── http.go │ │ │ └── server.go │ │ └── service │ │ │ ├── README.md │ │ │ ├── greeter.go │ │ │ ├── hello.go │ │ │ └── service.go │ ├── moon.go │ └── wire.go │ ├── gen │ ├── common_method.go │ ├── configs │ │ └── config.yaml │ ├── gen │ │ └── cmd.go │ └── gen_model.go │ ├── houyi │ ├── Makefile │ ├── configs │ │ ├── .gitignore │ │ └── config.yaml │ ├── houyi │ │ └── cmd.go │ ├── internal │ │ ├── biz │ │ │ ├── README.md │ │ │ ├── alert.go │ │ │ ├── bo │ │ │ │ ├── alert.go │ │ │ │ ├── alert_test.go │ │ │ │ ├── datasource_event.go │ │ │ │ ├── metric.go │ │ │ │ ├── strategy_domain.go │ │ │ │ ├── strategy_domain_test.go │ │ │ │ ├── strategy_event.go │ │ │ │ ├── strategy_http.go │ │ │ │ ├── strategy_http_test.go │ │ │ │ ├── strategy_logs.go │ │ │ │ ├── strategy_metric.go │ │ │ │ ├── strategy_metric_test.go │ │ │ │ └── strategy_ping.go │ │ │ ├── heartbeat.go │ │ │ ├── metric.go │ │ │ ├── register.go │ │ │ ├── repository │ │ │ │ ├── alert.go │ │ │ │ ├── cache_repo.go │ │ │ │ ├── heartbeat.go │ │ │ │ ├── metric.go │ │ │ │ └── strategy.go │ │ │ └── strategy.go │ │ ├── data │ │ │ ├── README.md │ │ │ ├── data.go │ │ │ ├── microserver │ │ │ │ ├── palace.go │ │ │ │ └── register.go │ │ │ └── repoimpl │ │ │ │ ├── alert.go │ │ │ │ ├── cache.go │ │ │ │ ├── heartbeat.go │ │ │ │ ├── metric.go │ │ │ │ ├── register.go │ │ │ │ └── strategy.go │ │ ├── houyiconf │ │ │ ├── .gitignore │ │ │ └── conf.proto │ │ ├── server │ │ │ ├── grpc.go │ │ │ ├── heartbeat.go │ │ │ ├── http.go │ │ │ ├── server.go │ │ │ ├── watch_alert.go │ │ │ ├── watch_event.go │ │ │ └── watch_strategy.go │ │ └── service │ │ │ ├── README.md │ │ │ ├── alert.go │ │ │ ├── build │ │ │ ├── alarm.go │ │ │ ├── alert.go │ │ │ ├── datasource.go │ │ │ ├── metric.go │ │ │ └── strategy.go │ │ │ ├── health.go │ │ │ ├── metric.go │ │ │ ├── register.go │ │ │ └── strategy.go │ ├── moon.go │ └── wire.go │ ├── palace │ ├── Makefile │ ├── configs │ │ ├── .gitignore │ │ ├── config.yaml │ │ └── toml │ │ │ └── config.toml │ ├── internal │ │ ├── biz │ │ │ ├── README.md │ │ │ ├── alarm.go │ │ │ ├── alarm_group.go │ │ │ ├── alarm_page.go │ │ │ ├── alarm_send.go │ │ │ ├── authorization.go │ │ │ ├── bo │ │ │ │ ├── alarm.go │ │ │ │ ├── alarm_raw.go │ │ │ │ ├── alarm_send.go │ │ │ │ ├── alert.go │ │ │ │ ├── auth │ │ │ │ │ ├── email.go │ │ │ │ │ ├── feishu.go │ │ │ │ │ ├── gitee.go │ │ │ │ │ ├── github.go │ │ │ │ │ └── oauth.go │ │ │ │ ├── authorization.go │ │ │ │ ├── captcha.go │ │ │ │ ├── dashboard.go │ │ │ │ ├── datasource.go │ │ │ │ ├── dict.go │ │ │ │ ├── file.go │ │ │ │ ├── history.go │ │ │ │ ├── hook.go │ │ │ │ ├── menu.go │ │ │ │ ├── metric.go │ │ │ │ ├── msg.go │ │ │ │ ├── resource.go │ │ │ │ ├── select.go │ │ │ │ ├── send_template.go │ │ │ │ ├── strategy.go │ │ │ │ ├── subscriber.go │ │ │ │ ├── team.go │ │ │ │ ├── team_invite.go │ │ │ │ ├── team_role.go │ │ │ │ ├── template.go │ │ │ │ ├── time_engine_rule.go │ │ │ │ └── user.go │ │ │ ├── captcha.go │ │ │ ├── dashboard.go │ │ │ ├── datasource.go │ │ │ ├── dict.go │ │ │ ├── file.go │ │ │ ├── history.go │ │ │ ├── hook.go │ │ │ ├── invite.go │ │ │ ├── menu.go │ │ │ ├── metric.go │ │ │ ├── microrepository │ │ │ │ ├── datasource_metric.go │ │ │ │ ├── send_alert.go │ │ │ │ ├── server_register.go │ │ │ │ └── strategy.go │ │ │ ├── register.go │ │ │ ├── repository │ │ │ │ ├── alarm.go │ │ │ │ ├── alarm_group.go │ │ │ │ ├── alarm_page_self.go │ │ │ │ ├── alarm_raw.go │ │ │ │ ├── alarm_send.go │ │ │ │ ├── cache.go │ │ │ │ ├── captcha.go │ │ │ │ ├── dashboard.go │ │ │ │ ├── datasource.go │ │ │ │ ├── datasource_metric.go │ │ │ │ ├── department.go │ │ │ │ ├── dict.go │ │ │ │ ├── file.go │ │ │ │ ├── history.go │ │ │ │ ├── hook.go │ │ │ │ ├── lock.go │ │ │ │ ├── menu.go │ │ │ │ ├── metric.go │ │ │ │ ├── msg.go │ │ │ │ ├── oauth_user.go │ │ │ │ ├── resource.go │ │ │ │ ├── send_template.go │ │ │ │ ├── statistics.go │ │ │ │ ├── strategy.go │ │ │ │ ├── strategy_group.go │ │ │ │ ├── subscriber.go │ │ │ │ ├── system.go │ │ │ │ ├── team.go │ │ │ │ ├── team_dict.go │ │ │ │ ├── team_invite.go │ │ │ │ ├── team_menu.go │ │ │ │ ├── team_resource.go │ │ │ │ ├── team_role.go │ │ │ │ ├── team_send_template.go │ │ │ │ ├── template.go │ │ │ │ ├── time_engine_rule.go │ │ │ │ ├── user.go │ │ │ │ └── user_message.go │ │ │ ├── resource.go │ │ │ ├── send_template.go │ │ │ ├── server_register.go │ │ │ ├── statistics.go │ │ │ ├── strategy.go │ │ │ ├── strategy_group.go │ │ │ ├── subscriber.go │ │ │ ├── system.go │ │ │ ├── team.go │ │ │ ├── team_role.go │ │ │ ├── template.go │ │ │ ├── time_engine_rule.go │ │ │ ├── user.go │ │ │ └── user_message.go │ │ ├── data │ │ │ ├── README.md │ │ │ ├── data.go │ │ │ ├── houyi_conn.go │ │ │ ├── init.go │ │ │ ├── microserver │ │ │ │ ├── datasource_metric.go │ │ │ │ ├── heartbeat.go │ │ │ │ ├── msg.go │ │ │ │ ├── register.go │ │ │ │ ├── send_alert.go │ │ │ │ └── strategy.go │ │ │ ├── rabbit_conn.go │ │ │ ├── register.go │ │ │ ├── repoimpl │ │ │ │ ├── alarm_group.go │ │ │ │ ├── alarm_page.go │ │ │ │ ├── alarm_raw.go │ │ │ │ ├── alarm_send.go │ │ │ │ ├── cache.go │ │ │ │ ├── captcha.go │ │ │ │ ├── dashboard.go │ │ │ │ ├── datasource.go │ │ │ │ ├── datasource_metric.go │ │ │ │ ├── dict.go │ │ │ │ ├── file.go │ │ │ │ ├── history.go │ │ │ │ ├── hook.go │ │ │ │ ├── invite.go │ │ │ │ ├── invite_email.html │ │ │ │ ├── lock.go │ │ │ │ ├── menu.go │ │ │ │ ├── metric.go │ │ │ │ ├── oauth_user.go │ │ │ │ ├── realtime_alarm.go │ │ │ │ ├── register.go │ │ │ │ ├── resource.go │ │ │ │ ├── send_template.go │ │ │ │ ├── statistics.go │ │ │ │ ├── strategroup.go │ │ │ │ ├── strategy.go │ │ │ │ ├── subscriber.go │ │ │ │ ├── system.go │ │ │ │ ├── team.go │ │ │ │ ├── team_dict.go │ │ │ │ ├── team_menu.go │ │ │ │ ├── team_resource.go │ │ │ │ ├── team_role.go │ │ │ │ ├── team_send_template.go │ │ │ │ ├── template.go │ │ │ │ ├── time_engine_rule.go │ │ │ │ ├── user.go │ │ │ │ ├── user_message.go │ │ │ │ ├── verify_email.html │ │ │ │ └── welcome.html │ │ │ ├── runtime │ │ │ │ ├── cache │ │ │ │ │ ├── entry.go │ │ │ │ │ ├── example │ │ │ │ │ │ └── example.go │ │ │ │ │ ├── init_test.go │ │ │ │ │ ├── inner_cache.go │ │ │ │ │ ├── inner_cache_test.go │ │ │ │ │ ├── interface.go │ │ │ │ │ ├── reader.go │ │ │ │ │ ├── reader_test.go │ │ │ │ │ ├── writer.go │ │ │ │ │ └── writer_test.go │ │ │ │ ├── interface.go │ │ │ │ ├── scheme.go │ │ │ │ └── scheme_test.go │ │ │ └── sendtemplate │ │ │ │ ├── send_dingtalk.tpl │ │ │ │ ├── send_email.html │ │ │ │ ├── send_feishu.json │ │ │ │ └── send_wechat.json │ │ ├── palaceconf │ │ │ ├── .gitignore │ │ │ └── conf.proto │ │ ├── server │ │ │ ├── alert_consumer.go │ │ │ ├── grpc.go │ │ │ ├── http.go │ │ │ ├── server.go │ │ │ └── strategy_watch.go │ │ └── service │ │ │ ├── README.md │ │ │ ├── alarm │ │ │ ├── alarm_notice_group.go │ │ │ ├── alarm_send.go │ │ │ └── timeenginerule.go │ │ │ ├── alert.go │ │ │ ├── authorization │ │ │ └── authorization.go │ │ │ ├── builder │ │ │ ├── alarm.go │ │ │ ├── alarm_notice_group.go │ │ │ ├── alarm_send.go │ │ │ ├── build.go │ │ │ ├── datasource.go │ │ │ ├── dict.go │ │ │ ├── file.go │ │ │ ├── history.go │ │ │ ├── hook.go │ │ │ ├── invite.go │ │ │ ├── menu.go │ │ │ ├── metric.go │ │ │ ├── metric_data.go │ │ │ ├── oauth.go │ │ │ ├── pagination.go │ │ │ ├── realtime_alarm.go │ │ │ ├── resource.go │ │ │ ├── role.go │ │ │ ├── send_template.go │ │ │ ├── strategy.go │ │ │ ├── subscriber.go │ │ │ ├── team.go │ │ │ ├── team_member.go │ │ │ ├── time_engine_rule.go │ │ │ └── user.go │ │ │ ├── datasource │ │ │ ├── datasource.go │ │ │ └── metric.go │ │ │ ├── dict │ │ │ └── dict.go │ │ │ ├── file │ │ │ └── file.go │ │ │ ├── health.go │ │ │ ├── history │ │ │ └── history.go │ │ │ ├── hook │ │ │ └── hook.go │ │ │ ├── invite │ │ │ └── invite.go │ │ │ ├── menu │ │ │ └── menu.go │ │ │ ├── realtime │ │ │ ├── alarm.go │ │ │ ├── alarmpageself.go │ │ │ ├── dashboard.go │ │ │ └── statistics.go │ │ │ ├── register.go │ │ │ ├── resource │ │ │ └── resource.go │ │ │ ├── server.go │ │ │ ├── strategy │ │ │ ├── strategy.go │ │ │ └── template.go │ │ │ ├── subscriber │ │ │ └── subscriber.go │ │ │ ├── system │ │ │ └── system.go │ │ │ ├── team │ │ │ ├── role.go │ │ │ └── team.go │ │ │ ├── template │ │ │ └── sendtemplate.go │ │ │ └── user │ │ │ ├── message.go │ │ │ └── user.go │ ├── moon.go │ ├── palace │ │ └── cmd.go │ └── wire.go │ ├── rabbit │ ├── Makefile │ ├── configs │ │ ├── .gitignore │ │ └── config.yaml │ ├── internal │ │ ├── biz │ │ │ ├── README.md │ │ │ ├── biz.go │ │ │ ├── bo │ │ │ │ ├── config.go │ │ │ │ └── msg.go │ │ │ ├── config.go │ │ │ ├── heartbeat.go │ │ │ ├── msg.go │ │ │ └── repository │ │ │ │ ├── cache_repo.go │ │ │ │ └── heartbeat.go │ │ ├── data │ │ │ ├── README.md │ │ │ ├── data.go │ │ │ ├── microserver │ │ │ │ ├── palace.go │ │ │ │ └── register.go │ │ │ └── repoimpl │ │ │ │ ├── cache.go │ │ │ │ ├── heartbeat.go │ │ │ │ └── register.go │ │ ├── rabbitconf │ │ │ ├── .gitignore │ │ │ └── conf.proto │ │ ├── server │ │ │ ├── consumer.go │ │ │ ├── grpc.go │ │ │ ├── heartbeat.go │ │ │ ├── http.go │ │ │ └── server.go │ │ └── service │ │ │ ├── README.md │ │ │ ├── config.go │ │ │ ├── health.go │ │ │ ├── hook.go │ │ │ └── service.go │ ├── moon.go │ ├── rabbit │ │ └── cmd.go │ └── wire.go │ └── stringer │ └── cmd.go ├── deploy ├── docker │ └── moon │ │ ├── README.md │ │ ├── docker-compose.yaml │ │ ├── houyi │ │ └── config.yaml │ │ ├── palace │ │ └── config.yaml │ │ └── rabbit │ │ └── config.yaml └── k8s │ └── moon │ ├── README.md │ ├── houyi │ ├── configmap.yaml │ ├── deployment.yaml │ └── service.yaml │ ├── moon-frontend │ ├── deployment.yaml │ ├── ingress.yaml │ └── service.yaml │ ├── palace │ ├── configmap.yaml │ ├── deployment.yaml │ ├── ingress.yaml │ └── service.yaml │ └── rabbit │ ├── configmap.yaml │ ├── deployment.yaml │ └── service.yaml ├── docs ├── i18n │ ├── quick-start.md │ └── zh-CN │ │ ├── dev.md │ │ ├── gopher.md │ │ └── quick-start.md ├── images │ ├── architecture-en.png │ ├── architecture.png │ ├── feishu-moon.png │ ├── goland-config.png │ ├── make-api.png │ ├── moon.svg │ └── prometheus-logo.svg └── openai │ └── oepnapi.yaml ├── entrypoint.sh ├── go.mod ├── go.sum ├── pkg ├── conf │ ├── conf.pb.go │ └── conf.proto ├── env │ └── env.go ├── helper │ ├── ai_chat.go │ ├── hello │ │ └── hello.go │ ├── metric │ │ ├── counter_alarm.go │ │ ├── counter_notify.go │ │ ├── counter_request.go │ │ ├── counter_request_err.go │ │ ├── gauge_alarm.go │ │ ├── histogram_response_time.go │ │ └── metric.go │ ├── middleware │ │ ├── cors.go │ │ ├── i18n.go │ │ ├── jwt.go │ │ ├── jwt_test.go │ │ ├── locale │ │ │ ├── active.en.toml │ │ │ └── active.zh.toml │ │ ├── logging.go │ │ ├── rbac.go │ │ ├── selector.go │ │ ├── sourcetype.go │ │ ├── timeout.go │ │ └── validate.go │ ├── pprof.go │ ├── sse │ │ ├── client.go │ │ ├── sse.go │ │ ├── sse.html │ │ └── sse_test.go │ └── string.go ├── houyi │ ├── datasource │ │ ├── config.go │ │ ├── datasource.go │ │ ├── datasource_test.go │ │ ├── domain.go │ │ ├── endpoint_duration.go │ │ ├── endpoint_duration_test.go │ │ ├── endpoint_ping.go │ │ ├── endpoint_port.go │ │ ├── log_response.go │ │ ├── metric.go │ │ ├── prometheus.go │ │ ├── prometheus_test.go │ │ ├── victoriametrics.go │ │ └── victoriametrics_test.go │ ├── logs │ │ ├── aliyun.go │ │ ├── elasticsearch.go │ │ ├── elasticsearch_test.go │ │ ├── logs.go │ │ ├── loki.go │ │ └── loki_test.go │ └── mq │ │ ├── mq.go │ │ └── mq_test.go ├── label │ ├── annotation.go │ ├── annotation_test.go │ ├── label.go │ └── label_test.go ├── merr │ ├── err.pb.go │ ├── err.proto │ └── err_errors.pb.go ├── notify │ ├── email │ │ └── email.go │ ├── hook │ │ ├── dintalk.go │ │ ├── feishu.go │ │ ├── notifyapp.go │ │ ├── other.go │ │ └── wechat.go │ ├── notify.go │ └── phone │ │ └── phone.go ├── palace │ ├── imodel │ │ ├── dict.go │ │ ├── model.go │ │ ├── resource.go │ │ └── send_template.go │ └── model │ │ ├── .gitignore │ │ ├── README-ER.md │ │ ├── README.md │ │ ├── alarmmodel │ │ ├── .gitignore │ │ ├── alarm_history.go │ │ ├── alarm_raw.go │ │ ├── alarm_send_history.go │ │ ├── history_details.go │ │ ├── init.go │ │ ├── realtime_alarm.go │ │ ├── realtime_arlarm_page.go │ │ ├── realtime_arlarm_receiver.go │ │ └── realtime_details.go │ │ ├── base_model.go │ │ ├── bizmodel │ │ ├── .gitignore │ │ ├── README-ER.md │ │ ├── README.md │ │ ├── alarm_group.go │ │ ├── alarm_hook.go │ │ ├── alarm_notice_member.go │ │ ├── alarm_page_self.go │ │ ├── base_model.go │ │ ├── casbin_rule.gen.go │ │ ├── dashboard.go │ │ ├── dashboard_chart.go │ │ ├── dashboard_self.go │ │ ├── datasource.go │ │ ├── datasource_metrics.go │ │ ├── init.go │ │ ├── metric_labels.go │ │ ├── send_strategy.go │ │ ├── strategy.go │ │ ├── strategy_group.go │ │ ├── strategy_group_categories.go │ │ ├── strategy_label_notice.go │ │ ├── strategy_level_domain.go │ │ ├── strategy_level_event.go │ │ ├── strategy_level_http.go │ │ ├── strategy_level_metric.go │ │ ├── strategy_level_metric_test.go │ │ ├── strategy_level_ping.go │ │ ├── strategy_level_port.go │ │ ├── strategy_level_template.go │ │ ├── strategy_levels.go │ │ ├── strategy_logs_level.go │ │ ├── strategy_subscribers.go │ │ ├── strategy_template.go │ │ ├── sys_dict.go │ │ ├── sys_send_template.go │ │ ├── sys_team_apis.go │ │ ├── sys_team_member_roles.go │ │ ├── sys_team_members.go │ │ ├── sys_team_menu.go │ │ ├── sys_team_role_apis.go │ │ ├── sys_team_roles.go │ │ ├── time_engine.go │ │ └── time_engine_rule.go │ │ ├── init.go │ │ ├── strategy_level_template.go │ │ ├── strategy_template.go │ │ ├── strategy_template_categories.go │ │ ├── sys_apis.go │ │ ├── sys_dict.go │ │ ├── sys_menu.go │ │ ├── sys_oauth_users.go │ │ ├── sys_send_template.go │ │ ├── sys_team_config.go │ │ ├── sys_team_invite.go │ │ ├── sys_teams.go │ │ ├── sys_user_message.go │ │ └── sys_users.go ├── plugin │ ├── cache │ │ ├── cache.go │ │ └── redis.go │ ├── event │ │ ├── event.go │ │ ├── kafka.go │ │ ├── mqtt.go │ │ └── rocketmq.go │ ├── microserver │ │ └── new.go │ ├── mlog │ │ ├── aliyun.go │ │ ├── log.go │ │ ├── loki.go │ │ ├── slog.go │ │ ├── stdout.go │ │ └── zaplog.go │ └── oss │ │ ├── alioss.go │ │ ├── local.go │ │ ├── minio.go │ │ ├── oss.go │ │ └── tencentoss.go ├── util │ ├── after │ │ └── recover.go │ ├── captcha │ │ ├── captcha.go │ │ └── captcha_test.go │ ├── cipher │ │ ├── ase.go │ │ └── config.go │ ├── codec │ │ ├── codec.go │ │ ├── toml.go │ │ └── yaml.go │ ├── conn │ │ ├── discovery.go │ │ ├── gorm.go │ │ ├── miniredis.go │ │ ├── miniredis_test.go │ │ ├── rbac │ │ │ ├── rbac.go │ │ │ └── rbac_model.conf │ │ ├── redis.go │ │ └── tracer.go │ ├── email │ │ ├── default.go │ │ └── email.go │ ├── file │ │ └── file.go │ ├── format │ │ ├── format.go │ │ └── format_test.go │ ├── go │ │ ├── go.go │ │ └── go_test.go │ ├── httpx │ │ ├── httpx.go │ │ └── httpx_test.go │ ├── ptr │ │ ├── ptr.go │ │ └── ptr_test.go │ ├── random │ │ ├── string.go │ │ ├── uuid.go │ │ └── uuid_test.go │ ├── response │ │ └── httpresponse.go │ ├── safety │ │ └── map.go │ ├── types │ │ ├── code.go │ │ ├── code_test.go │ │ ├── context.go │ │ ├── encoding.go │ │ ├── map.go │ │ ├── md5.go │ │ ├── nil.go │ │ ├── object.go │ │ ├── object_test.go │ │ ├── page.go │ │ ├── password.go │ │ ├── password_test.go │ │ ├── retry.go │ │ ├── slices.go │ │ ├── string.go │ │ ├── string_test.go │ │ ├── ternary.go │ │ ├── time.go │ │ ├── time_engine.go │ │ └── time_engine_test.go │ └── yaml │ │ └── yaml.go ├── vobj │ ├── .gitignore │ ├── alarmsendtype.go │ ├── alertstatus.go │ ├── allow.go │ ├── biztype.go │ ├── bytesize.go │ ├── condition.go │ ├── datasourcetype.go │ ├── dicttype.go │ ├── eventcondition.go │ ├── eventdatatype.go │ ├── gender.go │ ├── header.go │ ├── hookapp.go │ ├── httpmethod.go │ ├── invitetype.go │ ├── language.go │ ├── menutype.go │ ├── metrictype.go │ ├── moduletype.go │ ├── multidatasourcesustain.go │ ├── network.go │ ├── notifytype.go │ ├── oauthapp.go │ ├── realtimeaction.go │ ├── role.go │ ├── sendstatus.go │ ├── sendtype.go │ ├── sourcetype.go │ ├── status.go │ ├── storagetype.go │ ├── strategytemplatesource.go │ ├── strategytype.go │ ├── sustain.go │ ├── timeengineruletype.go │ ├── topic.go │ └── usermessagetype.go └── watch │ ├── README.md │ ├── handler.go │ ├── heap.go │ ├── metric.go │ ├── msg.go │ ├── queue.go │ ├── watch.go │ └── watch_test.go ├── pr.sh └── third_party ├── README.md ├── buf └── validate │ ├── expression.proto │ ├── priv │ └── private.proto │ └── validate.proto ├── errors └── errors.proto ├── google ├── api │ ├── annotations.proto │ ├── client.proto │ ├── field_behavior.proto │ ├── http.proto │ └── httpbody.proto └── protobuf │ ├── any.proto │ ├── api.proto │ ├── compiler │ └── plugin.proto │ ├── descriptor.proto │ ├── duration.proto │ ├── empty.proto │ ├── field_mask.proto │ ├── source_context.proto │ ├── struct.proto │ ├── timestamp.proto │ ├── type.proto │ └── wrappers.proto ├── openapi └── v3 │ ├── annotations.proto │ └── openapi.proto └── swagger_ui ├── .gitignore ├── index.html ├── logo.svg ├── rapidoc-min.js └── rapidoc-min.js.map /.github/workflows/deploy.yaml: -------------------------------------------------------------------------------- 1 | name: Docker Build and Push 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'd*' # 触发条件可以根据你的需求修改 7 | 8 | jobs: 9 | build-and-push: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - name: Checkout code 14 | uses: actions/checkout@v2 15 | 16 | - name: Login to Docker Hub 17 | run: echo "${{ secrets.REPO_PASS }}" | docker login -u "${{ secrets.REPO }}" --password-stdin 18 | 19 | - name: Build and push Docker image 20 | run: | 21 | docker build -t ${{ secrets.REPO }}/deploy -f DockerfileDeploy . 22 | docker push ${{ secrets.REPO }}/deploy:latest 23 | docker build -t ${{ secrets.REPO }}/build -f DockerfileBuild . 24 | docker push ${{ secrets.REPO }}/build:latest 25 | env: 26 | REPO: ${{ secrets.REPO }} 27 | REPO_PASS: ${{ secrets.REPO_PASS }} 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Reference https://github.com/github/gitignore/blob/master/Go.gitignore 2 | # Binaries for programs and plugins 3 | *.exe 4 | *.exe~ 5 | *.dll 6 | *.dylib 7 | 8 | # Test binary, built with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | 14 | # Dependency directories (remove the comment below to include it) 15 | vendor/ 16 | 17 | # Go workspace file 18 | go.work 19 | 20 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 21 | *.o 22 | *.a 23 | *.so 24 | 25 | # OS General 26 | Thumbs.db 27 | .DS_Store 28 | 29 | # project 30 | *.cert 31 | *.key 32 | *.log 33 | bin/ 34 | 35 | # Develop tools 36 | .vscode/ 37 | .idea/ 38 | *.swp 39 | tmp 40 | wire_gen.go 41 | api/*.*.go 42 | *.db* 43 | db_* 44 | -------------------------------------------------------------------------------- /.golangci.yaml: -------------------------------------------------------------------------------- 1 | run: 2 | go: '1.22.0' 3 | tests: false 4 | issues: 5 | exclude-dirs: 6 | - "third_party" 7 | - "api" 8 | linters: 9 | # disable-all: true # 关闭其他linter 10 | enable: #下面注释的部分是因为golang1.20和 golangci-lint 有兼容问题 11 | - asasalint 12 | - asciicheck 13 | - bidichk 14 | - bodyclose 15 | - durationcheck 16 | # - errcheck 17 | - errchkjson 18 | - errorlint 19 | # - exhaustive 20 | # - exportloopref 21 | - copyloopvar 22 | # - gosec 23 | - govet 24 | - loggercheck 25 | - makezero 26 | - nilerr 27 | - noctx 28 | - reassign 29 | - staticcheck 30 | - typecheck 31 | disable: 32 | - unused 33 | linters-settings: 34 | # errcheck: 35 | # check-type-assertions: true # 检查类型断言 36 | errorlint: 37 | errorf: true # 检查fmt.Errorf错误是否用%w 38 | gosec: 39 | excludes: 40 | - G401 # Detect the usage of DES, RC4, MD5 or SHA1 41 | - G501 # Import blocklist: crypto/md5 42 | - G502 # Import blocklist: crypto/des 43 | - G503 # Import blocklist: crypto/rc4 44 | - G504 # Import blocklist: net/http/cgi 45 | - G505 # Import blocklist: crypto/sha1 -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | #FROM golang:1.21.0 AS builder 2 | FROM aidemoonio/build:latest AS builder 3 | 4 | COPY . /src 5 | WORKDIR /src 6 | 7 | RUN make build 8 | 9 | #FROM debian:stable-slim 10 | FROM aidemoonio/deploy:latest 11 | 12 | WORKDIR /app 13 | 14 | ARG CMD_PARAMS="palace" 15 | ENV CMD_PARAMS_ENV=${CMD_PARAMS} 16 | ENV CONFIG_TYPE="yaml" 17 | # 复制脚本到容器中 18 | COPY entrypoint.sh /usr/local/bin/entrypoint.sh 19 | COPY --from=builder /src/bin/${CMD_PARAMS} /app/${CMD_PARAMS} 20 | COPY --from=builder /src/third_party/swagger_ui /app/third_party/swagger_ui/ 21 | 22 | EXPOSE 8000 23 | EXPOSE 9000 24 | VOLUME /data/conf 25 | # 设置 ENTRYPOINT 26 | ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] 27 | 28 | CMD ["sh"] 29 | -------------------------------------------------------------------------------- /DockerfileBuild: -------------------------------------------------------------------------------- 1 | FROM golang:1.23.0 2 | 3 | RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 648ACFD622F3D138 \ 4 | && echo "deb https://deb.debian.org/debian bookworm main" > /etc/apt/sources.list \ 5 | && echo "deb https://deb.debian.org/debian bookworm-updates main" >> /etc/apt/sources.list \ 6 | && echo "deb https://deb.debian.org/debian-security bookworm-security main" >> /etc/apt/sources.list 7 | 8 | RUN apt-get update -y \ 9 | && apt-get install -y protobuf-compiler 10 | 11 | RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest \ 12 | && go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest \ 13 | && go install github.com/go-kratos/kratos/cmd/kratos/v2@latest \ 14 | && go install github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2@latest \ 15 | && go install github.com/google/gnostic/cmd/protoc-gen-openapi@latest \ 16 | && go install github.com/google/wire/cmd/wire@latest \ 17 | && go install github.com/aide-cloud/protoc-gen-go-errors@latest 18 | -------------------------------------------------------------------------------- /DockerfileDeploy: -------------------------------------------------------------------------------- 1 | FROM debian:stable-slim 2 | 3 | RUN apt-get update -y && apt-get install -y --no-install-recommends \ 4 | apt-transport-https \ 5 | ca-certificates \ 6 | netbase \ 7 | && apt-get update -y \ 8 | && rm -rf /var/lib/apt/lists/* \ 9 | && apt-get autoremove -y && apt-get autoclean -y 10 | 11 | # 设置时区 12 | RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ 13 | echo "Asia/Shanghai" > /etc/timezone -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 go-kratos 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /api/.gitignore: -------------------------------------------------------------------------------- 1 | *.*.go -------------------------------------------------------------------------------- /api/admin/file/file.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package api.admin.file; 4 | 5 | option go_package = "github.com/aide-family/moon//api/admin/file;file"; 6 | option java_multiple_files = true; 7 | option java_package = ".api.admin.file"; 8 | 9 | // 文件管理模块 10 | service FileManage { 11 | } 12 | 13 | 14 | -------------------------------------------------------------------------------- /api/admin/system/system.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package api.admin.system; 4 | 5 | import "google/api/annotations.proto"; 6 | import "buf/validate/validate.proto"; 7 | 8 | option go_package = "github.com/aide-family/moon/api/admin/system;system"; 9 | option java_multiple_files = true; 10 | option java_package = "api.admin.system"; 11 | 12 | // 系统管理模块, 只对超级管理员开启 13 | service System { 14 | // 重置团队数据库 15 | rpc ResetTeam(ResetTeamRequest) returns (ResetTeamReply) { 16 | option (google.api.http) = { 17 | post: "/api/admin/system/team/reset" 18 | body: "*" 19 | }; 20 | } 21 | } 22 | 23 | message ResetTeamRequest { 24 | uint32 teamID = 1 [(buf.validate.field).cel = { 25 | message: "请先选择你要操作的团队" 26 | expression: "this > 0" 27 | }]; 28 | } 29 | message ResetTeamReply {} -------------------------------------------------------------------------------- /api/datasource.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package api; 4 | 5 | import "enum.proto"; 6 | 7 | option go_package = "github.com/aide-family/moon/api;api"; 8 | option java_multiple_files = true; 9 | option java_package = "api"; 10 | 11 | // 数据源基础交互数据类型 12 | message DatasourceItem { 13 | // 数据源类型 14 | DatasourceType category = 1; 15 | // 存储器类型 16 | StorageType storageType = 2; 17 | // 数据源配置 json 18 | string config = 3; 19 | // 数据源地址 20 | string endpoint = 4; 21 | // 数据源ID 22 | uint32 id = 5; 23 | // 状态 24 | Status status = 6; 25 | // 团队ID 26 | uint32 teamId = 7; 27 | } -------------------------------------------------------------------------------- /api/global.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package api; 4 | 5 | import "buf/validate/validate.proto"; 6 | 7 | option go_package = "github.com/aide-family/moon/api;api"; 8 | option java_multiple_files = true; 9 | option java_package = "api"; 10 | 11 | // 分页器件 12 | message PaginationReq { 13 | // 页码 14 | int32 pageNum = 1 [(buf.validate.field).cel = { 15 | expression: "this > 0", 16 | message: "分页页码必须大于0" 17 | }]; 18 | // 每页数量 19 | int32 pageSize = 2 [(buf.validate.field).cel = { 20 | expression: "this > 0 && this < 1000", 21 | message: "分页每页数量必须大于0且小于1000" 22 | }]; 23 | 24 | option (buf.validate.message).cel = { 25 | message: "最大翻页不能超过30000000", 26 | expression: "(this.pageNum * this.pageSize) < 30000000" 27 | }; 28 | } 29 | 30 | // 分页返回 31 | message PaginationReply { 32 | // 页码 33 | int32 pageNum = 1; 34 | // 每页数量 35 | int32 pageSize = 2; 36 | // 总条数 37 | int64 total = 3; 38 | } 39 | 40 | // 时间范围 41 | message TimeRangeReq { 42 | // 开始时间 43 | int64 start = 1; 44 | // 结束时间 45 | int64 end = 2; 46 | } 47 | -------------------------------------------------------------------------------- /api/health.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package api; 4 | 5 | import "google/api/annotations.proto"; 6 | 7 | option go_package = "github.com/aide-family/moon/api;api"; 8 | option java_multiple_files = true; 9 | option java_package = "api"; 10 | 11 | // 健康检查接口 12 | service Health { 13 | rpc Check(CheckRequest) returns (CheckReply) { 14 | option (google.api.http) = { 15 | get: "/health" 16 | }; 17 | } 18 | } 19 | 20 | message CheckRequest {} 21 | message CheckReply { 22 | bool healthy = 1; 23 | string version = 2; 24 | } -------------------------------------------------------------------------------- /api/helloworld/v1/error_reason.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package helloworld.v1; 4 | 5 | option go_package = "moon/api/helloworld/v1;v1"; 6 | option java_multiple_files = true; 7 | option java_package = "helloworld.v1"; 8 | option objc_class_prefix = "APIHelloworldV1"; 9 | 10 | enum ErrorReason { 11 | GREETER_UNSPECIFIED = 0; 12 | USER_NOT_FOUND = 1; 13 | } 14 | -------------------------------------------------------------------------------- /api/helloworld/v1/greeter.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package helloworld.v1; 4 | 5 | import "google/api/annotations.proto"; 6 | 7 | option go_package = "moon/api/helloworld/v1;v1"; 8 | option java_multiple_files = true; 9 | option java_package = "dev.kratos.api.helloworld.v1"; 10 | option java_outer_classname = "HelloworldProtoV1"; 11 | 12 | // The greeting service definition. 13 | service Greeter { 14 | // Sends a greeting 15 | rpc SayHello (HelloRequest) returns (HelloReply) { 16 | option (google.api.http) = { 17 | get: "/helloworld/{name}" 18 | }; 19 | } 20 | } 21 | 22 | // The request message containing the user's name. 23 | message HelloRequest { 24 | string name = 1; 25 | } 26 | 27 | // The response message containing the greetings 28 | message HelloReply { 29 | string message = 1; 30 | } 31 | -------------------------------------------------------------------------------- /api/houyi/alert/alert.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package api.houyi.alert; 4 | 5 | import "google/api/annotations.proto"; 6 | import "strategy.proto"; 7 | import "alert.proto"; 8 | 9 | option go_package = "github.com/aide-family/moon/api/houyi/alert;alert"; 10 | option java_multiple_files = true; 11 | option java_package = "api.houyi.alert"; 12 | 13 | service PushAlert { 14 | rpc Alarm (AlarmRequest) returns (AlarmReply) { 15 | option (google.api.http) = { 16 | post: "/v1/alert/alarm" 17 | body: "*" 18 | }; 19 | } 20 | } 21 | 22 | message AlarmRequest { 23 | // 策略 24 | MetricStrategyItem strategy = 1; 25 | } 26 | message AlarmReply { 27 | // 告警 28 | AlarmItem alarm = 1; 29 | } -------------------------------------------------------------------------------- /api/metadata.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package api; 4 | 5 | import "buf/validate/validate.proto"; 6 | import "enum.proto"; 7 | 8 | option go_package = "github.com/aide-family/moon/api;api"; 9 | option java_multiple_files = true; 10 | option java_package = "api"; 11 | 12 | // 指标标签值列表 13 | message MetricLabelValues { 14 | repeated string values = 1; 15 | } 16 | 17 | // 查询到的数据详情, 用与元数据构建 18 | message MetricDetail { 19 | // 指标名称 20 | string name = 1 [(buf.validate.field).cel = { 21 | message: "指标名称必须传递", 22 | expression: "this.size() > 0" 23 | }]; 24 | // 帮助信息 25 | string help = 2; 26 | // 类型 27 | MetricType type = 3 [(buf.validate.field).enum.defined_only = true]; 28 | // 标签集合 29 | map labels = 4; 30 | // 指标单位 31 | string unit = 5; 32 | } 33 | 34 | // Metric类型数据查询结果 35 | message MetricQueryResult { 36 | // 标签集合 37 | map labels = 1; 38 | // 结果类型 39 | string resultType = 2; 40 | // 结果值(图表) 41 | repeated MetricQueryValue values = 3; 42 | // 结果值(单数据) 43 | MetricQueryValue value = 4; 44 | } 45 | 46 | // 查询到的数据值 47 | message MetricQueryValue { 48 | // 值 49 | double value = 1; 50 | // 时间戳 51 | int64 timestamp = 2; 52 | } -------------------------------------------------------------------------------- /api/rabbit/hook/hook.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package api.rabbit.hook; 4 | 5 | import "google/api/annotations.proto"; 6 | 7 | option go_package = "github.com/aide-family/moon/api/rabbit/hook;hook"; 8 | option java_multiple_files = true; 9 | option java_package = "api.rabbit.hook"; 10 | 11 | // 用于接受外界需要推送的消息 12 | service Hook { 13 | // 发送消息, 用于接受http数据 14 | rpc SendMsg (SendMsgRequest) returns (SendMsgReply) { 15 | option (google.api.http) = { 16 | post: "/v1/rabbit/send/msg" 17 | body: "*" 18 | }; 19 | } 20 | } 21 | 22 | message SendMsgRequest { 23 | // 用于接收外界的数据, 兼容所有json格式 24 | string json = 1; 25 | // 用于匹配该数据发送给谁 26 | string route = 2; 27 | // 幂等性校验 28 | string requestID = 3; 29 | } 30 | message SendMsgReply { 31 | // 发送的结果 32 | string msg = 1; 33 | // 状态码 34 | int32 code = 2; 35 | // 发送时间 36 | string time = 3; 37 | } 38 | -------------------------------------------------------------------------------- /api/rabbit/push/config.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package api.rabbit.push; 4 | 5 | import "google/api/annotations.proto"; 6 | import "conf/conf.proto"; 7 | 8 | option go_package = "github.com/aide-family/moon/api/rabbit/push;push"; 9 | option java_multiple_files = true; 10 | option java_package = "api.rabbit.push"; 11 | 12 | service Config { 13 | rpc NotifyObject(NotifyObjectRequest) returns (NotifyObjectReply) { 14 | option (google.api.http) = { 15 | post: "/v1/rabbit/push/config" 16 | body: "*" 17 | }; 18 | } 19 | } 20 | 21 | message NotifyObjectRequest { 22 | // 根据路由匹配具体的发送对象 23 | map receivers = 4; 24 | map templates = 5; 25 | } 26 | message NotifyObjectReply { 27 | // 发送的结果 28 | string msg = 1; 29 | // 状态码 30 | int32 code = 2; 31 | // 发送时间 32 | string time = 3; 33 | } 34 | -------------------------------------------------------------------------------- /api/v1/hello.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package api.v1; 4 | 5 | import "google/api/annotations.proto"; 6 | 7 | option go_package = "github.com/aide-family/moon/api/v1;v1"; 8 | option java_multiple_files = true; 9 | option java_package = "api.v1"; 10 | 11 | // Hello模块接口定义 12 | service Hello { 13 | // 测试接口, 用于输出Hello 14 | rpc SayHello (SayHelloRequest) returns (SayHelloReply) { 15 | // 定义http路由 16 | option (google.api.http) = { 17 | post: "/v1/hello" 18 | body: "*" 19 | }; 20 | } 21 | } 22 | 23 | // 定义请求参数 24 | message SayHelloRequest { 25 | // 参数名称(对应请求方式,例如post请求,此数据会从body中获取) 26 | string name = 1; 27 | } 28 | // 定义响应参数 29 | message SayHelloReply { 30 | // 参数名称, 这些参数会以json的方式返回给请求方 31 | string message = 1; 32 | } -------------------------------------------------------------------------------- /build_images.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | VERSION=$(git describe --tags --always) 3 | echo $VERSION 4 | # 可执行文件列表 5 | executables=("palace" "rabbit" "houyi") 6 | 7 | # 遍历每个可执行文件并构建镜像 8 | for exec in "${executables[@]}"; do 9 | # 设置镜像名称,可以根据需要修改 10 | image_name="$1/${exec}:$VERSION" 11 | # 构建 Docker 镜像 12 | docker build --build-arg CMD_PARAMS=${exec} -t ${image_name} . 13 | # 打一个latest版本 14 | docker tag ${image_name} "$1/${exec}:latest" 15 | # 推送到 Docker 仓库 16 | docker push ${image_name} 17 | docker push "$1/${exec}:latest" 18 | echo "Built ${image_name} for executable ${exec}" 19 | done 20 | -------------------------------------------------------------------------------- /cmd/config/modeltype.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | const ( 4 | // MainCode 主库 5 | MainCode = "main" // 主库 6 | // BizModelCode 业务库 7 | BizModelCode = "biz" // 业务库 8 | // AlarmModelBizCode 告警库 9 | AlarmModelBizCode = "alarm" // 告警库 10 | ) 11 | 12 | const ( 13 | // MainPath 主库路径 14 | MainPath = "./pkg/palace/model/query" 15 | // BizModelPath 业务库路径 16 | BizModelPath = "./pkg/palace/model/bizmodel/bizquery" 17 | // AlarmModelBizPath 告警库路径 18 | AlarmModelBizPath = "./pkg/palace/model/alarmmodel/alarmquery" 19 | ) 20 | 21 | // GetModelPath 获取模型路径 22 | func GetModelPath(typeCode string) string { 23 | switch typeCode { 24 | case MainCode: 25 | return MainPath 26 | case BizModelCode: 27 | return BizModelPath 28 | case AlarmModelBizCode: 29 | return AlarmModelBizPath 30 | default: 31 | return MainPath 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /cmd/option/gen_model.go: -------------------------------------------------------------------------------- 1 | package option 2 | 3 | import ( 4 | "github.com/aide-family/moon/cmd/server/gen" 5 | 6 | "github.com/spf13/cobra" 7 | ) 8 | 9 | var ( 10 | datasource string 11 | drive string 12 | outputPath string 13 | modelType string 14 | ) 15 | 16 | var genCmd = &cobra.Command{ 17 | Use: "gen", 18 | Short: "gen", 19 | Long: `gen`, 20 | Example: `cmd gen`, 21 | Run: func(cmd *cobra.Command, args []string) { 22 | gen.Run(datasource, drive, modelType) 23 | }, 24 | } 25 | 26 | func init() { 27 | genCmd.Flags().StringVarP(&datasource, "datasource", "d", "", "datasource") 28 | genCmd.Flags().StringVarP(&drive, "drive", "r", "", "drive") 29 | genCmd.Flags().StringVarP(&outputPath, "output", "o", "", "output") 30 | genCmd.Flags().StringVarP(&modelType, "modelType", "m", "main", "model type") 31 | } 32 | -------------------------------------------------------------------------------- /cmd/option/root.go: -------------------------------------------------------------------------------- 1 | package option 2 | 3 | import ( 4 | "os" 5 | 6 | "github.com/aide-family/moon/pkg/util/types" 7 | 8 | "github.com/go-kratos/kratos/v2/log" 9 | "github.com/spf13/cobra" 10 | ) 11 | 12 | var rootCmd = &cobra.Command{ 13 | Run: func(cmd *cobra.Command, args []string) { 14 | log.Warn("Not Command") 15 | }, 16 | } 17 | 18 | // Execute executes the root command. 19 | func Execute() { 20 | rootCmd.AddCommand(serverCmd, versionCmd, genCmd) 21 | if err := rootCmd.Execute(); !types.IsNil(err) { 22 | log.Error(err) 23 | os.Exit(1) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /cmd/option/version.go: -------------------------------------------------------------------------------- 1 | package option 2 | 3 | import ( 4 | "github.com/go-kratos/kratos/v2/log" 5 | 6 | "github.com/spf13/cobra" 7 | ) 8 | 9 | var logFlag bool 10 | 11 | var versionCmd = &cobra.Command{ 12 | Use: "version", 13 | Short: "version", 14 | Long: `version info`, 15 | Example: `cmd version 16 | cmd v`, 17 | Run: func(cmd *cobra.Command, args []string) { 18 | log.Infow("name", "moon cli", "version", "0.0.1") 19 | showLog() 20 | }, 21 | } 22 | 23 | func init() { 24 | // --log时候显示日志 25 | versionCmd.Flags().BoolVarP(&logFlag, "log", "l", false, "show log") 26 | } 27 | 28 | func showLog() { 29 | if logFlag { 30 | log.Info("TODO 增加日志获取逻辑") 31 | // TODO 增加更新日志 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /cmd/server.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/aide-family/moon/cmd/option" 5 | "github.com/aide-family/moon/pkg/env" 6 | _ "go.uber.org/automaxprocs" 7 | ) 8 | 9 | // go build -ldflags "-X main.Version=x.y.z" 10 | var ( 11 | // Version is the version of the compiled software. 12 | Version string 13 | ) 14 | 15 | func main() { 16 | env.SetVersion(Version) 17 | option.Execute() 18 | } 19 | -------------------------------------------------------------------------------- /cmd/server/demo/demo/cmd.go: -------------------------------------------------------------------------------- 1 | //go:build ignore 2 | // +build ignore 3 | 4 | package main 5 | 6 | import ( 7 | "flag" 8 | 9 | _ "go.uber.org/automaxprocs" 10 | 11 | "github.com/aide-family/moon/cmd/server/demo" 12 | "github.com/aide-family/moon/pkg/env" 13 | ) 14 | 15 | // go build -ldflags "-X main.Version=x.y.z" 16 | var ( 17 | // flagconf is the config flag. 18 | flagconf string 19 | 20 | // Version is the version of the compiled software. 21 | Version string 22 | ) 23 | 24 | func init() { 25 | flag.StringVar(&flagconf, "c", "../configs", "config path, eg: -conf config.yaml") 26 | } 27 | 28 | func main() { 29 | flag.Parse() 30 | env.SetVersion(Version) 31 | demo.Run(flagconf) 32 | } 33 | -------------------------------------------------------------------------------- /cmd/server/demo/internal/biz/README.md: -------------------------------------------------------------------------------- 1 | # Biz 2 | -------------------------------------------------------------------------------- /cmd/server/demo/internal/biz/biz.go: -------------------------------------------------------------------------------- 1 | package biz 2 | 3 | import "github.com/google/wire" 4 | 5 | // ProviderSetBiz is biz providers. 6 | var ProviderSetBiz = wire.NewSet( 7 | NewGreeterUsecase, 8 | NewHelloBiz, 9 | ) 10 | -------------------------------------------------------------------------------- /cmd/server/demo/internal/biz/bo/select.go: -------------------------------------------------------------------------------- 1 | package bo 2 | 3 | type ( 4 | // SelectOptionBo select option 5 | SelectOptionBo struct { 6 | Value any `json:"value"` 7 | Label string `json:"label"` 8 | Disabled bool `json:"disabled"` 9 | } 10 | ) 11 | -------------------------------------------------------------------------------- /cmd/server/demo/internal/biz/hello.go: -------------------------------------------------------------------------------- 1 | package biz 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/cmd/server/demo/internal/biz/repository" 7 | ) 8 | 9 | // NewHelloBiz 实例化HelloBiz 10 | func NewHelloBiz(helloRepository repository.Hello) *HelloBiz { 11 | return &HelloBiz{ 12 | helloRepository: helloRepository, 13 | } 14 | } 15 | 16 | // HelloBiz . 17 | type HelloBiz struct { 18 | helloRepository repository.Hello 19 | } 20 | 21 | // SayHello 输出Hello {name} 22 | func (b *HelloBiz) SayHello(ctx context.Context, name string) (string, error) { 23 | return b.helloRepository.SayHello(ctx, name) 24 | } 25 | -------------------------------------------------------------------------------- /cmd/server/demo/internal/biz/repository/cache_repo.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "github.com/aide-family/moon/pkg/plugin/cache" 5 | ) 6 | 7 | // CacheRepo cache repo 8 | type CacheRepo interface { 9 | Cacher() cache.ICacher 10 | } 11 | -------------------------------------------------------------------------------- /cmd/server/demo/internal/biz/repository/hello.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "context" 5 | ) 6 | 7 | // Hello . 8 | type Hello interface { 9 | // SayHello . 10 | SayHello(ctx context.Context, name string) (string, error) 11 | } 12 | -------------------------------------------------------------------------------- /cmd/server/demo/internal/data/README.md: -------------------------------------------------------------------------------- 1 | # Data 2 | -------------------------------------------------------------------------------- /cmd/server/demo/internal/data/greeter.go: -------------------------------------------------------------------------------- 1 | package data 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/go-kratos/kratos/v2/log" 7 | 8 | "github.com/aide-family/moon/cmd/server/demo/internal/biz" 9 | ) 10 | 11 | type greeterRepo struct { 12 | data *Data 13 | log *log.Helper 14 | } 15 | 16 | // NewGreeterRepo . 17 | func NewGreeterRepo(data *Data) biz.GreeterRepo { 18 | logger := log.GetLogger() 19 | return &greeterRepo{ 20 | data: data, 21 | log: log.NewHelper(logger), 22 | } 23 | } 24 | 25 | func (r *greeterRepo) Save(ctx context.Context, g *biz.Greeter) (*biz.Greeter, error) { 26 | return g, nil 27 | } 28 | 29 | func (r *greeterRepo) Update(ctx context.Context, g *biz.Greeter) (*biz.Greeter, error) { 30 | return g, nil 31 | } 32 | 33 | func (r *greeterRepo) FindByID(context.Context, int64) (*biz.Greeter, error) { 34 | return nil, nil 35 | } 36 | 37 | func (r *greeterRepo) ListByHello(context.Context, string) ([]*biz.Greeter, error) { 38 | return nil, nil 39 | } 40 | 41 | func (r *greeterRepo) ListAll(context.Context) ([]*biz.Greeter, error) { 42 | return nil, nil 43 | } 44 | -------------------------------------------------------------------------------- /cmd/server/demo/internal/data/repoimpl/cache_repo_impl.go: -------------------------------------------------------------------------------- 1 | package repoimpl 2 | 3 | import ( 4 | "github.com/aide-family/moon/cmd/server/demo/internal/biz/repository" 5 | "github.com/aide-family/moon/cmd/server/demo/internal/data" 6 | "github.com/aide-family/moon/pkg/plugin/cache" 7 | ) 8 | 9 | // NewCacheRepo new cache repo. 10 | func NewCacheRepo(data *data.Data) repository.CacheRepo { 11 | return &cacheRepoImpl{data: data} 12 | } 13 | 14 | type cacheRepoImpl struct { 15 | data *data.Data 16 | } 17 | 18 | func (l *cacheRepoImpl) Cacher() cache.ICacher { 19 | return l.data.GetCacher() 20 | } 21 | -------------------------------------------------------------------------------- /cmd/server/demo/internal/data/repoimpl/hello.go: -------------------------------------------------------------------------------- 1 | package repoimpl 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/cmd/server/demo/internal/biz/repository" 7 | "github.com/aide-family/moon/cmd/server/demo/internal/data" 8 | ) 9 | 10 | // NewHelloRepository new hello repository. 11 | func NewHelloRepository(data *data.Data) repository.Hello { 12 | return &helloRepositoryImpl{data: data} 13 | } 14 | 15 | type helloRepositoryImpl struct { 16 | data *data.Data 17 | } 18 | 19 | func (h *helloRepositoryImpl) SayHello(ctx context.Context, name string) (string, error) { 20 | return "hello " + name, nil 21 | } 22 | -------------------------------------------------------------------------------- /cmd/server/demo/internal/data/repoimpl/repo_impl.go: -------------------------------------------------------------------------------- 1 | package repoimpl 2 | 3 | import ( 4 | "github.com/google/wire" 5 | ) 6 | 7 | // ProviderSetRepoImpl wire.ProviderSet 8 | var ProviderSetRepoImpl = wire.NewSet( 9 | NewCacheRepo, 10 | NewHelloRepository, 11 | ) 12 | -------------------------------------------------------------------------------- /cmd/server/demo/internal/democonf/.gitignore: -------------------------------------------------------------------------------- 1 | *.*.go -------------------------------------------------------------------------------- /cmd/server/demo/internal/server/grpc.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | import ( 4 | "github.com/aide-family/moon/cmd/server/demo/internal/democonf" 5 | "github.com/aide-family/moon/pkg/helper/middleware" 6 | "github.com/aide-family/moon/pkg/plugin/mlog" 7 | "github.com/bufbuild/protovalidate-go" 8 | "github.com/go-kratos/kratos/v2/middleware/recovery" 9 | "github.com/go-kratos/kratos/v2/transport/grpc" 10 | ) 11 | 12 | // NewGRPCServer new a gRPC server. 13 | func NewGRPCServer(bc *democonf.Bootstrap) *grpc.Server { 14 | c := bc.GetServer() 15 | opts := []grpc.ServerOption{ 16 | grpc.Middleware( 17 | recovery.Recovery(recovery.WithHandler(mlog.RecoveryHandle)), 18 | middleware.Validate(protovalidate.WithFailFast(true)), 19 | ), 20 | } 21 | if c.Grpc.Network != "" { 22 | opts = append(opts, grpc.Network(c.Grpc.Network)) 23 | } 24 | if c.Grpc.Addr != "" { 25 | opts = append(opts, grpc.Address(c.Grpc.Addr)) 26 | } 27 | if c.Grpc.Timeout != nil { 28 | opts = append(opts, grpc.Timeout(c.Grpc.Timeout.AsDuration())) 29 | } 30 | srv := grpc.NewServer(opts...) 31 | 32 | return srv 33 | } 34 | -------------------------------------------------------------------------------- /cmd/server/demo/internal/service/README.md: -------------------------------------------------------------------------------- 1 | # Service 2 | -------------------------------------------------------------------------------- /cmd/server/demo/internal/service/greeter.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "context" 5 | 6 | v1 "github.com/aide-family/moon/api/helloworld/v1" 7 | "github.com/aide-family/moon/cmd/server/demo/internal/biz" 8 | "github.com/aide-family/moon/pkg/util/types" 9 | ) 10 | 11 | // GreeterService is a greeter service. 12 | type GreeterService struct { 13 | v1.UnimplementedGreeterServer 14 | 15 | uc *biz.GreeterUsecase 16 | } 17 | 18 | // NewGreeterService new a greeter service. 19 | func NewGreeterService(uc *biz.GreeterUsecase) *GreeterService { 20 | return &GreeterService{uc: uc} 21 | } 22 | 23 | // SayHello implements helloworld.GreeterServer. 24 | func (s *GreeterService) SayHello(ctx context.Context, in *v1.HelloRequest) (*v1.HelloReply, error) { 25 | g, err := s.uc.CreateGreeter(ctx, &biz.Greeter{Hello: in.Name}) 26 | if !types.IsNil(err) { 27 | return nil, err 28 | } 29 | return &v1.HelloReply{Message: "Hello " + g.Hello}, nil 30 | } 31 | -------------------------------------------------------------------------------- /cmd/server/demo/internal/service/hello.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "context" 5 | 6 | v1api "github.com/aide-family/moon/api/v1" 7 | "github.com/aide-family/moon/cmd/server/demo/internal/biz" 8 | ) 9 | 10 | // HelloService is a greeter service. 11 | type HelloService struct { 12 | v1api.UnimplementedHelloServer 13 | 14 | helloBiz *biz.HelloBiz 15 | } 16 | 17 | // NewHelloService new a greeter service. 18 | func NewHelloService(helloBiz *biz.HelloBiz) *HelloService { 19 | return &HelloService{ 20 | helloBiz: helloBiz, 21 | } 22 | } 23 | 24 | // SayHello implements helloworld.GreeterServer 25 | func (s *HelloService) SayHello(ctx context.Context, req *v1api.SayHelloRequest) (*v1api.SayHelloReply, error) { 26 | hello, err := s.helloBiz.SayHello(ctx, req.GetName()) 27 | if err != nil { 28 | return nil, err 29 | } 30 | return &v1api.SayHelloReply{ 31 | Message: hello, 32 | }, nil 33 | } 34 | -------------------------------------------------------------------------------- /cmd/server/demo/internal/service/service.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "github.com/google/wire" 5 | ) 6 | 7 | // ProviderSetService is service providers. 8 | var ProviderSetService = wire.NewSet( 9 | NewGreeterService, 10 | NewHelloService, 11 | ) 12 | -------------------------------------------------------------------------------- /cmd/server/demo/wire.go: -------------------------------------------------------------------------------- 1 | //go:build wireinject 2 | // +build wireinject 3 | 4 | // The build tag makes sure the stub is not built in the final build. 5 | 6 | package demo 7 | 8 | import ( 9 | "github.com/aide-family/moon/cmd/server/demo/internal/biz" 10 | "github.com/aide-family/moon/cmd/server/demo/internal/data" 11 | "github.com/aide-family/moon/cmd/server/demo/internal/data/repoimpl" 12 | "github.com/aide-family/moon/cmd/server/demo/internal/democonf" 13 | "github.com/aide-family/moon/cmd/server/demo/internal/server" 14 | "github.com/aide-family/moon/cmd/server/demo/internal/service" 15 | "github.com/go-kratos/kratos/v2" 16 | "github.com/go-kratos/kratos/v2/log" 17 | "github.com/google/wire" 18 | ) 19 | 20 | // wireApp init kratos application. 21 | func wireApp(*democonf.Bootstrap, log.Logger) (*kratos.App, func(), error) { 22 | panic(wire.Build( 23 | server.ProviderSetServer, 24 | data.ProviderSetData, 25 | repoimpl.ProviderSetRepoImpl, 26 | biz.ProviderSetBiz, 27 | service.ProviderSetService, 28 | newApp, 29 | )) 30 | } 31 | -------------------------------------------------------------------------------- /cmd/server/gen/configs/config.yaml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aide-family/moon/026ab5a5f1686673f02e89de87ef5fc7a909fcd5/cmd/server/gen/configs/config.yaml -------------------------------------------------------------------------------- /cmd/server/gen/gen/cmd.go: -------------------------------------------------------------------------------- 1 | //go:build ignore 2 | // +build ignore 3 | 4 | package main 5 | 6 | import ( 7 | "flag" 8 | 9 | "github.com/aide-family/moon/cmd/server/gen" 10 | ) 11 | 12 | var ( 13 | datasource string 14 | drive string 15 | outputPath string 16 | modelType string 17 | ) 18 | 19 | func init() { 20 | flag.StringVar(&datasource, "d", "", "datasource") 21 | flag.StringVar(&drive, "r", "mysql", "drive") 22 | flag.StringVar(&outputPath, "o", "./pkg/helper/model/query", "output") 23 | flag.StringVar(&modelType, "m", "main", "model type") 24 | } 25 | 26 | func main() { 27 | flag.Parse() 28 | gen.Run(datasource, drive, modelType) 29 | } 30 | -------------------------------------------------------------------------------- /cmd/server/houyi/configs/.gitignore: -------------------------------------------------------------------------------- 1 | local.yaml 2 | ectype* -------------------------------------------------------------------------------- /cmd/server/houyi/houyi/cmd.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | 6 | _ "go.uber.org/automaxprocs" 7 | 8 | "github.com/aide-family/moon/pkg/helper" 9 | 10 | "github.com/aide-family/moon/cmd/server/houyi" 11 | "github.com/aide-family/moon/pkg/env" 12 | ) 13 | 14 | // go build -ldflags "-X main.Version=x.y.z" 15 | var ( 16 | // flagconf is the config flag. 17 | flagconf string 18 | 19 | // configType is the config file type. 20 | configType string 21 | 22 | // Version is the version of the compiled software. 23 | Version string 24 | 25 | // pprofAddress is the pprof address. 26 | pprofAddress string 27 | ) 28 | 29 | func init() { 30 | flag.StringVar(&flagconf, "c", "../configs", "config path, eg: -c ./configs") 31 | flag.StringVar(&configType, "config_ext", "yaml", "config file ext name, eg: -config_ext yaml") 32 | flag.StringVar(&pprofAddress, "pprof_address", "", "pprof address, eg: -pprof_address 0.0.0.0:6060") 33 | } 34 | 35 | func main() { 36 | flag.Parse() 37 | env.SetVersion(Version) 38 | helper.Pprof(pprofAddress) 39 | houyi.Run(flagconf, configType) 40 | } 41 | -------------------------------------------------------------------------------- /cmd/server/houyi/internal/biz/README.md: -------------------------------------------------------------------------------- 1 | # Biz 2 | -------------------------------------------------------------------------------- /cmd/server/houyi/internal/biz/bo/alert_test.go: -------------------------------------------------------------------------------- 1 | package bo 2 | 3 | import ( 4 | "testing" 5 | "time" 6 | 7 | "github.com/aide-family/moon/pkg/label" 8 | "github.com/aide-family/moon/pkg/util/types" 9 | "github.com/aide-family/moon/pkg/vobj" 10 | ) 11 | 12 | func TestAlert_AlertJson(t *testing.T) { 13 | alert := &Alert{ 14 | Status: vobj.AlertStatusFiring, 15 | Labels: label.NewLabels(map[string]string{}), 16 | Annotations: make(label.Annotations), 17 | StartsAt: types.NewTime(time.Now()), 18 | EndsAt: &types.Time{}, 19 | GeneratorURL: "", 20 | Fingerprint: "", 21 | Value: 0, 22 | } 23 | t.Log(alert) 24 | } 25 | -------------------------------------------------------------------------------- /cmd/server/houyi/internal/biz/bo/datasource_event.go: -------------------------------------------------------------------------------- 1 | package bo 2 | 3 | import ( 4 | "strconv" 5 | 6 | "github.com/aide-family/moon/pkg/conf" 7 | "github.com/aide-family/moon/pkg/util/types" 8 | "github.com/aide-family/moon/pkg/vobj" 9 | "github.com/aide-family/moon/pkg/watch" 10 | ) 11 | 12 | var _ watch.Indexer = (*EventDatasource)(nil) 13 | 14 | // EventDatasource MQ 数据源配置 15 | type EventDatasource struct { 16 | TeamID uint32 `json:"team_id"` 17 | ID uint32 `json:"id"` 18 | Status vobj.Status `json:"status"` 19 | 20 | Conf *conf.Event `json:"conf"` 21 | } 22 | 23 | // Index 实现 watch.Indexer 接口 24 | func (m *EventDatasource) Index() string { 25 | return types.TextJoin(strconv.Itoa(int(m.TeamID)), ":", strconv.Itoa(int(m.ID))) 26 | } 27 | 28 | // String 实现 fmt.Stringer 接口 29 | func (m *EventDatasource) String() string { 30 | bs, _ := types.Marshal(m) 31 | return string(bs) 32 | } 33 | 34 | // GetConfig 获取 MQ 配置 35 | func (m *EventDatasource) GetConfig() *conf.Event { 36 | if m == nil { 37 | return nil 38 | } 39 | return m.Conf 40 | } 41 | -------------------------------------------------------------------------------- /cmd/server/houyi/internal/biz/heartbeat.go: -------------------------------------------------------------------------------- 1 | package biz 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/api" 7 | "github.com/aide-family/moon/cmd/server/houyi/internal/biz/repository" 8 | ) 9 | 10 | // NewHeartbeatBiz 创建心跳业务 11 | func NewHeartbeatBiz(heartbeatRepository repository.Heartbeat) *HeartbeatBiz { 12 | return &HeartbeatBiz{ 13 | heartbeatRepository: heartbeatRepository, 14 | } 15 | } 16 | 17 | // HeartbeatBiz 心跳业务 18 | type HeartbeatBiz struct { 19 | heartbeatRepository repository.Heartbeat 20 | } 21 | 22 | // Heartbeat 心跳 23 | func (h *HeartbeatBiz) Heartbeat(ctx context.Context, in *api.HeartbeatRequest) error { 24 | return h.heartbeatRepository.Heartbeat(ctx, in) 25 | } 26 | -------------------------------------------------------------------------------- /cmd/server/houyi/internal/biz/metric.go: -------------------------------------------------------------------------------- 1 | package biz 2 | 3 | import ( 4 | "context" 5 | "time" 6 | 7 | "github.com/aide-family/moon/cmd/server/houyi/internal/biz/bo" 8 | "github.com/aide-family/moon/cmd/server/houyi/internal/biz/repository" 9 | "github.com/aide-family/moon/pkg/houyi/datasource" 10 | ) 11 | 12 | // NewMetricBiz new MetricBiz 13 | func NewMetricBiz(metricRepository repository.Metric) *MetricBiz { 14 | return &MetricBiz{ 15 | metricRepository: metricRepository, 16 | } 17 | } 18 | 19 | // MetricBiz . 20 | type MetricBiz struct { 21 | metricRepository repository.Metric 22 | } 23 | 24 | // SyncMetrics 同步数据源元数据 25 | func (b *MetricBiz) SyncMetrics(ctx context.Context, datasourceInfo *bo.GetMetricsParams) ([]*bo.MetricDetail, error) { 26 | return b.metricRepository.GetMetrics(ctx, datasourceInfo) 27 | } 28 | 29 | // Query 查询数据 30 | func (b *MetricBiz) Query(ctx context.Context, req *bo.QueryQLParams) ([]*datasource.QueryResponse, error) { 31 | return b.metricRepository.Query(ctx, req) 32 | } 33 | 34 | // PushMetric 推送数据 35 | func (b *MetricBiz) PushMetric(req *bo.PushMetricParams) error { 36 | ctx, cancel := context.WithTimeout(context.Background(), 50*time.Second) 37 | defer cancel() 38 | return b.metricRepository.PushMetric(ctx, req) 39 | } 40 | -------------------------------------------------------------------------------- /cmd/server/houyi/internal/biz/register.go: -------------------------------------------------------------------------------- 1 | package biz 2 | 3 | import "github.com/google/wire" 4 | 5 | // ProviderSetBiz is biz providers. 6 | var ProviderSetBiz = wire.NewSet( 7 | NewMetricBiz, 8 | NewStrategyBiz, 9 | NewAlertBiz, 10 | NewHeartbeatBiz, 11 | ) 12 | -------------------------------------------------------------------------------- /cmd/server/houyi/internal/biz/repository/alert.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/cmd/server/houyi/internal/biz/bo" 7 | ) 8 | 9 | // Alert . 10 | type Alert interface { 11 | // SaveAlarm 保存告警 12 | SaveAlarm(ctx context.Context, alarm *bo.Alarm) error 13 | // PushAlarm 推送告警 14 | PushAlarm(ctx context.Context, alarm *bo.Alarm) error 15 | } 16 | -------------------------------------------------------------------------------- /cmd/server/houyi/internal/biz/repository/cache_repo.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "github.com/aide-family/moon/pkg/plugin/cache" 5 | ) 6 | 7 | // CacheRepo 换成统一repo 8 | type CacheRepo interface { 9 | // Cacher 获取缓存实现 10 | Cacher() cache.ICacher 11 | } 12 | -------------------------------------------------------------------------------- /cmd/server/houyi/internal/biz/repository/heartbeat.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/api" 7 | ) 8 | 9 | // Heartbeat . 10 | type Heartbeat interface { 11 | Heartbeat(ctx context.Context, in *api.HeartbeatRequest) error 12 | } 13 | -------------------------------------------------------------------------------- /cmd/server/houyi/internal/biz/repository/metric.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/cmd/server/houyi/internal/biz/bo" 7 | "github.com/aide-family/moon/pkg/houyi/datasource" 8 | ) 9 | 10 | // Metric . 11 | type Metric interface { 12 | // GetMetrics 获取指标列表 13 | GetMetrics(ctx context.Context, datasourceInfo *bo.GetMetricsParams) ([]*bo.MetricDetail, error) 14 | 15 | // Query 查询QL数据 16 | Query(ctx context.Context, req *bo.QueryQLParams) ([]*datasource.QueryResponse, error) 17 | 18 | // PushMetric 推送 19 | PushMetric(ctx context.Context, req *bo.PushMetricParams) error 20 | } 21 | -------------------------------------------------------------------------------- /cmd/server/houyi/internal/biz/repository/strategy.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/cmd/server/houyi/internal/biz/bo" 7 | ) 8 | 9 | // Strategy . 10 | type Strategy interface { 11 | // Save 保存策略 12 | Save(ctx context.Context, strategies []bo.IStrategy) error 13 | 14 | // Eval 策略评估 15 | Eval(ctx context.Context, strategy bo.IStrategy) (*bo.Alarm, error) 16 | } 17 | -------------------------------------------------------------------------------- /cmd/server/houyi/internal/biz/strategy.go: -------------------------------------------------------------------------------- 1 | package biz 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/cmd/server/houyi/internal/biz/bo" 7 | "github.com/aide-family/moon/cmd/server/houyi/internal/biz/repository" 8 | ) 9 | 10 | // NewStrategyBiz new StrategyBiz 11 | func NewStrategyBiz(strategyRepository repository.Strategy) *StrategyBiz { 12 | return &StrategyBiz{ 13 | strategyRepository: strategyRepository, 14 | } 15 | } 16 | 17 | // StrategyBiz . 18 | type StrategyBiz struct { 19 | strategyRepository repository.Strategy 20 | } 21 | 22 | // SaveStrategy 保存策略信息 23 | func (s *StrategyBiz) SaveStrategy(ctx context.Context, strategies []bo.IStrategy) error { 24 | return s.strategyRepository.Save(ctx, strategies) 25 | } 26 | 27 | // Eval 根据策略信息产生告警数据 28 | func (s *StrategyBiz) Eval(ctx context.Context, strategy bo.IStrategy) (*bo.Alarm, error) { 29 | return s.strategyRepository.Eval(ctx, strategy) 30 | } 31 | -------------------------------------------------------------------------------- /cmd/server/houyi/internal/data/README.md: -------------------------------------------------------------------------------- 1 | # Data 2 | -------------------------------------------------------------------------------- /cmd/server/houyi/internal/data/microserver/register.go: -------------------------------------------------------------------------------- 1 | package microserver 2 | 3 | import ( 4 | "github.com/google/wire" 5 | ) 6 | 7 | // ProviderSetRPCConn wire set 8 | var ProviderSetRPCConn = wire.NewSet( 9 | NewPalaceConn, 10 | ) 11 | -------------------------------------------------------------------------------- /cmd/server/houyi/internal/data/repoimpl/cache.go: -------------------------------------------------------------------------------- 1 | package repoimpl 2 | 3 | import ( 4 | "github.com/aide-family/moon/cmd/server/houyi/internal/biz/repository" 5 | "github.com/aide-family/moon/cmd/server/houyi/internal/data" 6 | "github.com/aide-family/moon/pkg/plugin/cache" 7 | ) 8 | 9 | // NewCacheRepo 实例化缓存仓库 10 | func NewCacheRepo(data *data.Data) repository.CacheRepo { 11 | return &cacheRepoImpl{data: data} 12 | } 13 | 14 | type cacheRepoImpl struct { 15 | data *data.Data 16 | } 17 | 18 | // Cacher 获取缓存仓库 19 | func (l *cacheRepoImpl) Cacher() cache.ICacher { 20 | return l.data.GetCacher() 21 | } 22 | -------------------------------------------------------------------------------- /cmd/server/houyi/internal/data/repoimpl/heartbeat.go: -------------------------------------------------------------------------------- 1 | package repoimpl 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/api" 7 | "github.com/aide-family/moon/cmd/server/houyi/internal/biz/repository" 8 | "github.com/aide-family/moon/cmd/server/houyi/internal/data/microserver" 9 | ) 10 | 11 | // NewHeartbeatRepository 初始化心跳存储层 12 | func NewHeartbeatRepository(palaceConn *microserver.PalaceConn) repository.Heartbeat { 13 | return &heartbeatRepositoryImpl{ 14 | palaceConn: palaceConn, 15 | } 16 | } 17 | 18 | type heartbeatRepositoryImpl struct { 19 | palaceConn *microserver.PalaceConn 20 | } 21 | 22 | func (h *heartbeatRepositoryImpl) Heartbeat(ctx context.Context, in *api.HeartbeatRequest) error { 23 | _, err := h.palaceConn.Heartbeat(ctx, in) 24 | 25 | return err 26 | } 27 | -------------------------------------------------------------------------------- /cmd/server/houyi/internal/data/repoimpl/register.go: -------------------------------------------------------------------------------- 1 | package repoimpl 2 | 3 | import ( 4 | "github.com/google/wire" 5 | ) 6 | 7 | // ProviderSetRepoImpl wire Set 8 | var ProviderSetRepoImpl = wire.NewSet( 9 | NewCacheRepo, 10 | NewMetricRepository, 11 | NewStrategyRepository, 12 | NewAlertRepository, 13 | NewHeartbeatRepository, 14 | ) 15 | -------------------------------------------------------------------------------- /cmd/server/houyi/internal/houyiconf/.gitignore: -------------------------------------------------------------------------------- 1 | *.*.go -------------------------------------------------------------------------------- /cmd/server/houyi/internal/service/README.md: -------------------------------------------------------------------------------- 1 | # Service 2 | -------------------------------------------------------------------------------- /cmd/server/houyi/internal/service/health.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/api" 7 | "github.com/aide-family/moon/cmd/server/houyi/internal/biz" 8 | "github.com/aide-family/moon/pkg/env" 9 | ) 10 | 11 | // HealthService 健康检查 12 | type HealthService struct { 13 | api.UnimplementedHealthServer 14 | 15 | heartbeatBiz *biz.HeartbeatBiz 16 | } 17 | 18 | // NewHealthService 创建健康检查服务 19 | func NewHealthService(heartbeatBiz *biz.HeartbeatBiz) *HealthService { 20 | return &HealthService{ 21 | heartbeatBiz: heartbeatBiz, 22 | } 23 | } 24 | 25 | // Check 检查 26 | func (s *HealthService) Check(_ context.Context, _ *api.CheckRequest) (*api.CheckReply, error) { 27 | return &api.CheckReply{Healthy: true, Version: env.Version()}, nil 28 | } 29 | 30 | // Heartbeat 心跳 31 | func (s *HealthService) Heartbeat(ctx context.Context, in *api.HeartbeatRequest) error { 32 | return s.heartbeatBiz.Heartbeat(ctx, in) 33 | } 34 | -------------------------------------------------------------------------------- /cmd/server/houyi/internal/service/register.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "github.com/google/wire" 5 | ) 6 | 7 | // ProviderSetService is service providers. 8 | var ProviderSetService = wire.NewSet( 9 | NewMetricService, 10 | NewHealthService, 11 | NewStrategyService, 12 | NewAlertService, 13 | ) 14 | -------------------------------------------------------------------------------- /cmd/server/houyi/wire.go: -------------------------------------------------------------------------------- 1 | //go:build wireinject 2 | // +build wireinject 3 | 4 | // The build tag makes sure the stub is not built in the final build. 5 | 6 | package houyi 7 | 8 | import ( 9 | "github.com/aide-family/moon/cmd/server/houyi/internal/biz" 10 | "github.com/aide-family/moon/cmd/server/houyi/internal/data" 11 | "github.com/aide-family/moon/cmd/server/houyi/internal/data/microserver" 12 | "github.com/aide-family/moon/cmd/server/houyi/internal/data/repoimpl" 13 | "github.com/aide-family/moon/cmd/server/houyi/internal/houyiconf" 14 | "github.com/aide-family/moon/cmd/server/houyi/internal/server" 15 | "github.com/aide-family/moon/cmd/server/houyi/internal/service" 16 | "github.com/go-kratos/kratos/v2" 17 | "github.com/go-kratos/kratos/v2/log" 18 | "github.com/google/wire" 19 | ) 20 | 21 | // wireApp init kratos application. 22 | func wireApp(*houyiconf.Bootstrap, log.Logger) (*kratos.App, func(), error) { 23 | panic(wire.Build( 24 | server.ProviderSetServer, 25 | data.ProviderSetData, 26 | repoimpl.ProviderSetRepoImpl, 27 | biz.ProviderSetBiz, 28 | service.ProviderSetService, 29 | microserver.ProviderSetRPCConn, 30 | newApp, 31 | )) 32 | } 33 | -------------------------------------------------------------------------------- /cmd/server/palace/configs/.gitignore: -------------------------------------------------------------------------------- 1 | local.yaml -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/README.md: -------------------------------------------------------------------------------- 1 | # Biz 2 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/alarm_page.go: -------------------------------------------------------------------------------- 1 | package biz 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/cmd/server/palace/internal/biz/repository" 7 | "github.com/aide-family/moon/pkg/palace/model/bizmodel" 8 | ) 9 | 10 | // NewAlarmPageBiz 创建告警页面管理功能 11 | func NewAlarmPageBiz(alarmPageRepository repository.AlarmPage) *AlarmPageBiz { 12 | return &AlarmPageBiz{ 13 | alarmPageRepository: alarmPageRepository, 14 | } 15 | } 16 | 17 | // AlarmPageBiz 告警页面管理功能 18 | type AlarmPageBiz struct { 19 | alarmPageRepository repository.AlarmPage 20 | } 21 | 22 | // UpdateAlarmPage 更新告警页面 23 | func (b *AlarmPageBiz) UpdateAlarmPage(ctx context.Context, userID uint32, alarmPageIDs []uint32) error { 24 | return b.alarmPageRepository.ReplaceAlarmPages(ctx, userID, alarmPageIDs) 25 | } 26 | 27 | // ListAlarmPage 告警页面列表 28 | func (b *AlarmPageBiz) ListAlarmPage(ctx context.Context, userID uint32) ([]*bizmodel.AlarmPageSelf, error) { 29 | return b.alarmPageRepository.ListAlarmPages(ctx, userID) 30 | } 31 | 32 | // GetAlertCounts 获取告警数量 33 | func (b *AlarmPageBiz) GetAlertCounts(ctx context.Context, pageIDs []uint32) map[int32]int64 { 34 | return b.alarmPageRepository.GetAlertCounts(ctx, pageIDs) 35 | } 36 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/bo/alarm_raw.go: -------------------------------------------------------------------------------- 1 | package bo 2 | 3 | import "github.com/aide-family/moon/pkg/vobj" 4 | 5 | type ( 6 | 7 | // CreateAlarmRawParams 创建告警原始数据参数 8 | CreateAlarmRawParams struct { 9 | Fingerprint string `json:"fingerprint"` 10 | RawInfo string `json:"rawInfo"` 11 | Receiver string `json:"receiver"` 12 | } 13 | 14 | // GetTeamStrategyParams 获取团队策略参数 15 | GetTeamStrategyParams struct { 16 | TeamID uint32 `json:"teamId"` 17 | StrategyID uint32 `json:"strategyId"` 18 | } 19 | 20 | // GetTeamStrategyLevelParams 获取团队策略等级参数 21 | GetTeamStrategyLevelParams struct { 22 | TeamID uint32 `json:"teamId"` 23 | LevelID uint32 `json:"level"` 24 | StrategyType vobj.StrategyType `json:"strategyType"` 25 | } 26 | 27 | // GetTeamDatasourceParams 获取团队数据源信息参数 28 | GetTeamDatasourceParams struct { 29 | TeamID uint32 `json:"teamId"` 30 | DatasourceIds []uint32 `json:"datasourceIds"` 31 | } 32 | ) 33 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/bo/auth/email.go: -------------------------------------------------------------------------------- 1 | package auth 2 | 3 | // EmailLoginParams 邮箱登录参数 4 | type EmailLoginParams struct { 5 | Code string `json:"code"` 6 | Email string `json:"email"` 7 | } 8 | 9 | // RegisterWithEmailParams 邮箱注册参数 10 | type RegisterWithEmailParams struct { 11 | Email string `json:"email"` 12 | Password string `json:"password"` 13 | Username string `json:"username"` 14 | } 15 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/bo/authorization.go: -------------------------------------------------------------------------------- 1 | package bo 2 | 3 | import ( 4 | "github.com/aide-family/moon/pkg/helper/middleware" 5 | "github.com/aide-family/moon/pkg/palace/model" 6 | "github.com/aide-family/moon/pkg/palace/model/bizmodel" 7 | ) 8 | 9 | // CheckPermissionParams 鉴权请求参数 10 | type CheckPermissionParams struct { 11 | JwtClaims *middleware.JwtClaims 12 | Operation string 13 | } 14 | 15 | // CheckTokenParams token鉴权请求参数 16 | type CheckTokenParams struct { 17 | JwtClaims *middleware.JwtClaims 18 | } 19 | 20 | // LoginParams 登录请求参数 21 | type LoginParams struct { 22 | Username string 23 | Password string // 加密后的密码 24 | Team uint32 // 对应团队ID 25 | } 26 | 27 | // LoginReply 登录响应 28 | type LoginReply struct { 29 | JwtClaims *middleware.JwtClaims 30 | User *model.SysUser 31 | } 32 | 33 | // LogoutParams 登出请求参数 34 | type LogoutParams struct { 35 | JwtClaims *middleware.JwtClaims 36 | } 37 | 38 | // RefreshTokenParams 刷新token请求参数 39 | type RefreshTokenParams struct { 40 | JwtClaims *middleware.JwtClaims 41 | Team uint32 // 对应团队ID 42 | } 43 | 44 | // RefreshTokenReply 刷新token响应 45 | type RefreshTokenReply struct { 46 | JwtClaims *middleware.JwtClaims 47 | User *model.SysUser 48 | Member *bizmodel.SysTeamMember 49 | } 50 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/bo/file.go: -------------------------------------------------------------------------------- 1 | package bo 2 | 3 | import ( 4 | "bytes" 5 | "mime/multipart" 6 | ) 7 | 8 | type ( 9 | 10 | // UploadFileParams 上传文件参数 11 | UploadFileParams struct { 12 | FileName string `json:"fileName"` 13 | BytesBuff *bytes.Buffer `json:"bytesBuff"` 14 | // 文件后最 15 | Extension string `json:"extension"` 16 | } 17 | 18 | // ConvertFileParams 转换文件参数 19 | ConvertFileParams struct { 20 | UploadType string `json:"uploadType"` 21 | File multipart.File `json:"file"` 22 | Filename string `json:"filename"` 23 | } 24 | // UploadResParams 上传文件返回参数 25 | UploadResParams struct { 26 | URL string `json:"url"` 27 | } 28 | 29 | // DownLoadFileParams 下载文件参数 30 | DownLoadFileParams struct { 31 | FilePath string `json:"filePath"` 32 | } 33 | ) 34 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/bo/history.go: -------------------------------------------------------------------------------- 1 | package bo 2 | 3 | import ( 4 | "github.com/aide-family/moon/pkg/util/types" 5 | "github.com/aide-family/moon/pkg/vobj" 6 | ) 7 | 8 | type ( 9 | // QueryAlarmHistoryListParams 查询告警历史列表请求参数 10 | QueryAlarmHistoryListParams struct { 11 | Keyword string `json:"keyword"` 12 | Page types.Pagination `json:"page"` 13 | AlertStatus []vobj.AlertStatus `json:"alertStatus"` 14 | // 告警时间范围 15 | EventAtStart string 16 | EventAtEnd string 17 | // 告警恢复时间 18 | ResolvedAtStart string 19 | ResolvedAtEnd string 20 | AlarmPage uint32 21 | } 22 | 23 | // GetAlarmHistoryParams 获取告警告警历史参数 24 | GetAlarmHistoryParams struct { 25 | // 告警ID 26 | ID uint32 `json:"id"` 27 | } 28 | ) 29 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/bo/hook.go: -------------------------------------------------------------------------------- 1 | package bo 2 | 3 | import ( 4 | "github.com/aide-family/moon/pkg/util/types" 5 | "github.com/aide-family/moon/pkg/vobj" 6 | ) 7 | 8 | type ( 9 | 10 | // CreateAlarmHookParams 创建hook参数 11 | CreateAlarmHookParams struct { 12 | // Hook的名称 13 | Name string `json:"name"` 14 | // hook说明信息 15 | Remark string `json:"remark"` 16 | // url 17 | URL string `json:"url"` 18 | // secret 19 | Secret string `json:"secret"` 20 | // hook app 21 | HookApp vobj.HookAPP `json:"hookApp"` 22 | // status 23 | Status vobj.Status `json:"status"` 24 | } 25 | 26 | // QueryAlarmHookListParams 查询hook列表 27 | QueryAlarmHookListParams struct { 28 | Keyword string `json:"keyword"` 29 | Page types.Pagination 30 | Name string 31 | Status vobj.Status 32 | Apps []vobj.HookAPP 33 | } 34 | 35 | // UpdateAlarmHookParams 更新hook参数 36 | UpdateAlarmHookParams struct { 37 | ID uint32 `json:"id"` 38 | UpdateParam *CreateAlarmHookParams `json:"updateParam"` 39 | } 40 | 41 | // UpdateAlarmHookStatusParams 更新hook状态 42 | UpdateAlarmHookStatusParams struct { 43 | IDs []uint32 `json:"ids"` 44 | Status vobj.Status 45 | } 46 | ) 47 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/bo/msg.go: -------------------------------------------------------------------------------- 1 | package bo 2 | 3 | import ( 4 | hookapi "github.com/aide-family/moon/api/rabbit/hook" 5 | "github.com/aide-family/moon/pkg/watch" 6 | ) 7 | 8 | type ( 9 | // Message 消息明细 10 | Message struct { 11 | Data map[string]any 12 | } 13 | ) 14 | 15 | var _ watch.Indexer = (*SendMsg)(nil) 16 | 17 | // SendMsg 发送消息 18 | type SendMsg struct { 19 | *hookapi.SendMsgRequest 20 | } 21 | 22 | // Index 生成发送消息索引 23 | func (s *SendMsg) Index() string { 24 | return s.RequestID 25 | } 26 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/bo/send_template.go: -------------------------------------------------------------------------------- 1 | package bo 2 | 3 | import ( 4 | "github.com/aide-family/moon/pkg/util/types" 5 | "github.com/aide-family/moon/pkg/vobj" 6 | ) 7 | 8 | type ( 9 | // CreateSendTemplate 创建发送模板 10 | CreateSendTemplate struct { 11 | // Name 模板名称 12 | Name string `json:"name"` 13 | // Content 模板内容 14 | Content string `json:"content"` 15 | // SendType 发送类型 16 | SendType vobj.AlarmSendType `json:"sendType"` 17 | // Status 状态 18 | Status vobj.Status `json:"status"` 19 | // Remark 备注 20 | Remark string `json:"remark"` 21 | } 22 | // UpdateSendTemplate 更新发送模板 23 | UpdateSendTemplate struct { 24 | ID uint32 `json:"id"` 25 | UpdateParam *CreateSendTemplate `json:"updateParam"` 26 | } 27 | 28 | // QuerySendTemplateListParams 查询发送模板列表参数 29 | QuerySendTemplateListParams struct { 30 | Page types.Pagination 31 | Keyword string `json:"keyword"` 32 | Status vobj.Status `json:"status"` 33 | SendTypes []vobj.AlarmSendType `json:"sendTypes"` 34 | } 35 | 36 | // UpdateSendTemplateStatusParams 更新发送模板状态 37 | UpdateSendTemplateStatusParams struct { 38 | Ids []uint32 `json:"ids"` 39 | Status vobj.Status `json:"status"` 40 | } 41 | ) 42 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/bo/subscriber.go: -------------------------------------------------------------------------------- 1 | package bo 2 | 3 | import ( 4 | "github.com/aide-family/moon/pkg/util/types" 5 | "github.com/aide-family/moon/pkg/vobj" 6 | ) 7 | 8 | type ( 9 | // SubscriberStrategyParams 用户订阅策略参数 10 | SubscriberStrategyParams struct { 11 | StrategyID uint32 `json:"strategy_id"` 12 | NotifyType vobj.NotifyType `json:"notify_type"` 13 | UserID uint32 `json:"user_id"` 14 | } 15 | 16 | // UnSubscriberStrategyParams 用户取消订阅 17 | UnSubscriberStrategyParams struct { 18 | StrategyID uint32 `json:"strategy_id"` 19 | UserID uint32 `json:"user_id"` 20 | } 21 | 22 | // QueryStrategySubscriberParams 策略订阅者参数 23 | QueryStrategySubscriberParams struct { 24 | Page types.Pagination 25 | StrategyID uint32 `json:"strategy_id"` 26 | NotifyType vobj.NotifyType `json:"notify_type"` 27 | } 28 | // QueryUserSubscriberParams 用户订阅策略列表查询参数 29 | QueryUserSubscriberParams struct { 30 | UserID uint32 `json:"user_id"` 31 | NotifyType vobj.NotifyType `json:"notify_type"` 32 | Page types.Pagination 33 | } 34 | ) 35 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/bo/team_role.go: -------------------------------------------------------------------------------- 1 | package bo 2 | 3 | import ( 4 | "github.com/aide-family/moon/pkg/util/types" 5 | "github.com/aide-family/moon/pkg/vobj" 6 | ) 7 | 8 | type ( 9 | // CreateTeamRoleParams 创建团队角色 10 | CreateTeamRoleParams struct { 11 | // 角色名称 12 | Name string `json:"name"` 13 | // 角色描述 14 | Remark string `json:"remark"` 15 | // 角色状态 16 | Status vobj.Status `json:"status"` 17 | // 角色权限 18 | Permissions []uint32 `json:"permissions"` 19 | } 20 | 21 | // UpdateTeamRoleParams 更新团队角色 22 | UpdateTeamRoleParams struct { 23 | ID uint32 `json:"id"` 24 | // 角色名称 25 | Name string `json:"name"` 26 | // 角色描述 27 | Remark string `json:"remark"` 28 | // 角色权限 29 | Permissions []uint32 `json:"permissions"` 30 | } 31 | 32 | // ListTeamRoleParams 获取团队角色列表 33 | ListTeamRoleParams struct { 34 | TeamID uint32 `json:"teamID"` 35 | Keyword string `json:"keyword"` 36 | Page types.Pagination `json:"page"` 37 | } 38 | ) 39 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/history.go: -------------------------------------------------------------------------------- 1 | package biz 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/cmd/server/palace/internal/biz/bo" 7 | "github.com/aide-family/moon/cmd/server/palace/internal/biz/repository" 8 | "github.com/aide-family/moon/pkg/palace/model/alarmmodel" 9 | ) 10 | 11 | type ( 12 | // AlarmHistoryBiz 告警历史相关业务逻辑 13 | AlarmHistoryBiz struct { 14 | historyRepository repository.HistoryRepository 15 | } 16 | ) 17 | 18 | // NewAlarmHistoryBiz 创建告警历史业务逻辑 19 | func NewAlarmHistoryBiz(historyRepository repository.HistoryRepository) *AlarmHistoryBiz { 20 | return &AlarmHistoryBiz{ 21 | historyRepository: historyRepository, 22 | } 23 | } 24 | 25 | // GetAlarmHistory 获取告警历史 26 | func (a *AlarmHistoryBiz) GetAlarmHistory(ctx context.Context, param *bo.GetAlarmHistoryParams) (*alarmmodel.AlarmHistory, error) { 27 | return a.historyRepository.GetAlarmHistory(ctx, param) 28 | } 29 | 30 | // ListAlarmHistories 获取告警历史列表 31 | func (a *AlarmHistoryBiz) ListAlarmHistories(ctx context.Context, param *bo.QueryAlarmHistoryListParams) ([]*alarmmodel.AlarmHistory, error) { 32 | return a.historyRepository.GetAlarmHistories(ctx, param) 33 | } 34 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/microrepository/datasource_metric.go: -------------------------------------------------------------------------------- 1 | package microrepository 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/cmd/server/palace/internal/biz/bo" 7 | "github.com/aide-family/moon/pkg/palace/model/bizmodel" 8 | ) 9 | 10 | // DatasourceMetric . 11 | type DatasourceMetric interface { 12 | // GetMetadata 同步指标元数据 13 | GetMetadata(ctx context.Context, datasourceInfo *bizmodel.Datasource) ([]*bizmodel.DatasourceMetric, error) 14 | 15 | // InitiateSyncRequest 发起同步请求 16 | InitiateSyncRequest(ctx context.Context, datasourceInfo *bizmodel.Datasource) error 17 | 18 | // Query 查询指标数据 19 | Query(ctx context.Context, req *bo.DatasourceQueryParams) ([]*bo.MetricQueryData, error) 20 | } 21 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/microrepository/send_alert.go: -------------------------------------------------------------------------------- 1 | package microrepository 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/cmd/server/palace/internal/biz/bo" 7 | ) 8 | 9 | // SendAlert 发送告警事件接口 10 | type SendAlert interface { 11 | // Send 发送告警事件 12 | Send(context.Context, *bo.SendMsg) 13 | } 14 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/microrepository/server_register.go: -------------------------------------------------------------------------------- 1 | package microrepository 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/api" 7 | ) 8 | 9 | // ServerRegister 子服务注册方法 10 | type ServerRegister interface { 11 | // Heartbeat 心跳 12 | Heartbeat(context.Context, *api.HeartbeatRequest) error 13 | // GetServerList 获取服务列表 14 | GetServerList(context.Context, *api.GetServerListRequest) (*api.GetServerListReply, error) 15 | } 16 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/microrepository/strategy.go: -------------------------------------------------------------------------------- 1 | package microrepository 2 | 3 | import ( 4 | "context" 5 | 6 | strategyapi "github.com/aide-family/moon/api/houyi/strategy" 7 | ) 8 | 9 | // Strategy 微服务策略推送 10 | type Strategy interface { 11 | // Push 推送策略 12 | Push(ctx context.Context, strategies *strategyapi.PushStrategyRequest) error 13 | } 14 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/register.go: -------------------------------------------------------------------------------- 1 | package biz 2 | 3 | import "github.com/google/wire" 4 | 5 | // ProviderSetBiz is biz providers. 6 | var ProviderSetBiz = wire.NewSet( 7 | NewUserBiz, 8 | NewCaptchaBiz, 9 | NewAuthorizationBiz, 10 | NewResourceBiz, 11 | NewTeamBiz, 12 | NewTeamRoleBiz, 13 | NewMenuBiz, 14 | NewDatasourceBiz, 15 | NewStrategyBiz, 16 | NewStrategyGroupBiz, 17 | NewStrategyCountBiz, 18 | NewMetricBiz, 19 | NewDictBiz, 20 | NewTemplateBiz, 21 | NewAlarmBiz, 22 | NewDashboardBiz, 23 | NewAlarmGroupBiz, 24 | NewAlarmPageBiz, 25 | NewSubscriptionStrategyBiz, 26 | NewAlarmHookBiz, 27 | NewAlarmHistoryBiz, 28 | NewInviteBiz, 29 | NewUserMessageBiz, 30 | NewServerRegisterBiz, 31 | NewFileBiz, 32 | NewSystemBiz, 33 | NewAlarmSendBiz, 34 | NewTimeEngineRuleBiz, 35 | NewSendTemplateBiz, 36 | NewStatisticsBiz, 37 | ) 38 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/repository/alarm_group.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/cmd/server/palace/internal/biz/bo" 7 | "github.com/aide-family/moon/pkg/palace/model/bizmodel" 8 | ) 9 | 10 | type ( 11 | // AlarmGroup 告警组接口 12 | AlarmGroup interface { 13 | // CreateAlarmGroup 创建告警组 14 | CreateAlarmGroup(context.Context, *bo.CreateAlarmNoticeGroupParams) (*bizmodel.AlarmNoticeGroup, error) 15 | // UpdateAlarmGroup 更新告警组 16 | UpdateAlarmGroup(context.Context, *bo.UpdateAlarmNoticeGroupParams) error 17 | // DeleteAlarmGroup 删除告警组 18 | DeleteAlarmGroup(context.Context, uint32) error 19 | // GetAlarmGroup 获取告警详情 20 | GetAlarmGroup(context.Context, uint32) (*bizmodel.AlarmNoticeGroup, error) 21 | GetAlarmGroupsByIDs(context.Context, []uint32) ([]*bizmodel.AlarmNoticeGroup, error) 22 | // AlarmGroupPage 告警列表 23 | AlarmGroupPage(context.Context, *bo.QueryAlarmNoticeGroupListParams) ([]*bizmodel.AlarmNoticeGroup, error) 24 | // UpdateStatus 更新状态 25 | UpdateStatus(context.Context, *bo.UpdateAlarmNoticeGroupStatusParams) error 26 | // MyAlarmGroups 获取我的告警组 27 | MyAlarmGroups(ctx context.Context, params *bo.MyAlarmGroupListParams) ([]*bizmodel.AlarmNoticeGroup, error) 28 | } 29 | ) 30 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/repository/alarm_page_self.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/pkg/palace/model/bizmodel" 7 | ) 8 | 9 | // AlarmPage 告警页面管理 10 | type AlarmPage interface { 11 | // ReplaceAlarmPages 批量替换告警页面 12 | ReplaceAlarmPages(ctx context.Context, userID uint32, alarmPageIDs []uint32) error 13 | 14 | // ListAlarmPages 获取用户告警页面列表 15 | ListAlarmPages(ctx context.Context, userID uint32) ([]*bizmodel.AlarmPageSelf, error) 16 | 17 | // GetAlertCounts 获取告警页面的告警数量 18 | GetAlertCounts(ctx context.Context, pageIDs []uint32) map[int32]int64 19 | } 20 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/repository/alarm_raw.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/cmd/server/palace/internal/biz/bo" 7 | "github.com/aide-family/moon/pkg/palace/model/alarmmodel" 8 | ) 9 | 10 | type ( 11 | // AlarmRaw repository 12 | AlarmRaw interface { 13 | // CreateAlarmRaws 创建告警原始数据 14 | CreateAlarmRaws(ctx context.Context, params []*bo.CreateAlarmRawParams, teamID uint32) ([]*alarmmodel.AlarmRaw, error) 15 | } 16 | ) 17 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/repository/alarm_send.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/cmd/server/palace/internal/biz/bo" 7 | "github.com/aide-family/moon/pkg/palace/model/alarmmodel" 8 | ) 9 | 10 | type ( 11 | 12 | // AlarmSendRepository is a AlarmSend repo. 13 | AlarmSendRepository interface { 14 | // GetAlarmSendHistory 获取告警发送历史 15 | GetAlarmSendHistory(ctx context.Context, param *bo.GetAlarmSendHistoryParams) (*alarmmodel.AlarmSendHistory, error) 16 | // AlarmSendHistoryList 获取告警发送历史列表 17 | AlarmSendHistoryList(ctx context.Context, param *bo.QueryAlarmSendHistoryListParams) ([]*alarmmodel.AlarmSendHistory, error) 18 | // SaveAlarmSendHistory 保存告警发送记录 19 | SaveAlarmSendHistory(ctx context.Context, param *bo.CreateAlarmSendParams) error 20 | // RetryAlarmSend 重试告警发送 21 | RetryAlarmSend(ctx context.Context, param *bo.RetryAlarmSendParams) error 22 | // GetRetryNumberByRequestID 获取重试次数 23 | GetRetryNumberByRequestID(ctx context.Context, requestID string, teamID uint32) (int, error) 24 | } 25 | ) 26 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/repository/captcha.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "context" 5 | "time" 6 | 7 | "github.com/aide-family/moon/cmd/server/palace/internal/biz/bo" 8 | ) 9 | 10 | // Captcha 验证码接口 11 | type Captcha interface { 12 | // CreateCaptcha 创建验证码 13 | CreateCaptcha(ctx context.Context, captcha *bo.ValidateCaptchaItem, duration time.Duration) error 14 | // GetCaptchaById 通过id获取验证码详情 15 | GetCaptchaByID(ctx context.Context, id string) (*bo.ValidateCaptchaItem, error) 16 | } 17 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/repository/datasource_metric.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/pkg/palace/model/bizmodel" 7 | ) 8 | 9 | // DatasourceMetric 数据源指标接口 10 | type DatasourceMetric interface { 11 | // CreateMetrics 创建指标 12 | CreateMetrics(context.Context, ...*bizmodel.DatasourceMetric) error 13 | 14 | // CreateMetricsNoAuth 创建指标(不鉴权) 15 | CreateMetricsNoAuth(context.Context, uint32, ...*bizmodel.DatasourceMetric) error 16 | } 17 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/repository/department.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | // Department . 4 | type Department interface { 5 | // TODO 增加接口方法 6 | } 7 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/repository/dict.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/cmd/server/palace/internal/biz/bo" 7 | "github.com/aide-family/moon/pkg/palace/imodel" 8 | ) 9 | 10 | type ( 11 | // Dict 字典接口 12 | Dict interface { 13 | // Create 创建字典 14 | Create(context.Context, *bo.CreateDictParams) (imodel.IDict, error) 15 | 16 | // GetByID 通过id 获取字典详情 17 | GetByID(context.Context, uint32) (imodel.IDict, error) 18 | 19 | // FindByPage 分页查询字典列表 20 | FindByPage(context.Context, *bo.QueryDictListParams) ([]imodel.IDict, error) 21 | 22 | // DeleteByID 通过ID删除字典 23 | DeleteByID(context.Context, uint32) error 24 | 25 | // UpdateStatusByIds 通过ID列表批量更新字典状态 26 | UpdateStatusByIds(context.Context, *bo.UpdateDictStatusParams) error 27 | 28 | // UpdateByID 通过ID更新字典数据 29 | UpdateByID(context.Context, *bo.UpdateDictParams) error 30 | } 31 | ) 32 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/repository/file.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "context" 5 | "io" 6 | 7 | "github.com/aide-family/moon/cmd/server/palace/internal/biz/bo" 8 | ) 9 | 10 | // FileRepository file repository interface 11 | type FileRepository interface { 12 | // UploadFile 上传文件 13 | UploadFile(ctx context.Context, params *bo.UploadFileParams) (string, error) 14 | 15 | DownLoadFile(ctx context.Context, params *bo.DownLoadFileParams) (io.ReadCloser, error) 16 | } 17 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/repository/history.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/cmd/server/palace/internal/biz/bo" 7 | "github.com/aide-family/moon/pkg/palace/model/alarmmodel" 8 | ) 9 | 10 | type ( 11 | // HistoryRepository 告警历史仓库接口 12 | HistoryRepository interface { 13 | // GetAlarmHistory 获取告警历史 14 | GetAlarmHistory(ctx context.Context, param *bo.GetAlarmHistoryParams) (*alarmmodel.AlarmHistory, error) 15 | // GetAlarmHistories 获取告警历史列表 16 | GetAlarmHistories(ctx context.Context, param *bo.QueryAlarmHistoryListParams) ([]*alarmmodel.AlarmHistory, error) 17 | // CreateAlarmHistory 创建告警历史 18 | CreateAlarmHistory(ctx context.Context, param *bo.CreateAlarmInfoParams) error 19 | } 20 | ) 21 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/repository/hook.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/cmd/server/palace/internal/biz/bo" 7 | "github.com/aide-family/moon/pkg/palace/model/bizmodel" 8 | ) 9 | 10 | type ( 11 | // AlarmHook 告警hook 12 | AlarmHook interface { 13 | // CreateAlarmHook 创建告警hook 14 | CreateAlarmHook(ctx context.Context, params *bo.CreateAlarmHookParams) (*bizmodel.AlarmHook, error) 15 | // UpdateAlarmHook 更新告警hook 16 | UpdateAlarmHook(ctx context.Context, params *bo.UpdateAlarmHookParams) error 17 | // DeleteAlarmHook 删除告警hook 18 | DeleteAlarmHook(ctx context.Context, ID uint32) error 19 | // GetAlarmHook 获取告警hook 20 | GetAlarmHook(ctx context.Context, ID uint32) (*bizmodel.AlarmHook, error) 21 | // ListAlarmHook 获取告警hook列表 22 | ListAlarmHook(ctx context.Context, params *bo.QueryAlarmHookListParams) ([]*bizmodel.AlarmHook, error) 23 | // UpdateAlarmHookStatus 更新告警hook状态 24 | UpdateAlarmHookStatus(ctx context.Context, params *bo.UpdateAlarmHookStatusParams) error 25 | } 26 | ) 27 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/repository/lock.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "context" 5 | "time" 6 | ) 7 | 8 | // Lock . 9 | type Lock interface { 10 | // Lock 加锁 11 | Lock(ctx context.Context, key string, expire time.Duration) error 12 | // UnLock 解锁 13 | UnLock(ctx context.Context, key string) error 14 | } 15 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/repository/menu.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/cmd/server/palace/internal/biz/bo" 7 | "github.com/aide-family/moon/pkg/palace/model" 8 | "github.com/aide-family/moon/pkg/vobj" 9 | ) 10 | 11 | // Menu 系统菜单接口 12 | type Menu interface { 13 | // Create 创建系统菜单 14 | Create(context.Context, *bo.CreateMenuParams) (*model.SysMenu, error) 15 | // BatchCreate 批量创建系统菜单 16 | BatchCreate(context.Context, []*bo.CreateMenuParams) error 17 | 18 | // UpdateById 更新系统菜单 19 | UpdateByID(context.Context, *bo.UpdateMenuParams) error 20 | // DeleteById 删除系统菜单 21 | DeleteByID(context.Context, uint32) error 22 | // GetByID 根据id获取系统菜单 23 | GetByID(context.Context, uint32) (*model.SysMenu, error) 24 | // FindByPage 分页查询系统菜单 25 | FindByPage(context.Context, *bo.QueryMenuListParams) ([]*model.SysMenu, error) 26 | // ListAll 获取所有系统菜单 27 | ListAll(context.Context) ([]*model.SysMenu, error) 28 | // UpdateStatusByIds 更新系统菜单状态 29 | UpdateStatusByIds(context.Context, vobj.Status, ...uint32) error 30 | // UpdateTypeByIds 更新系统菜单类型 31 | UpdateTypeByIds(context.Context, vobj.MenuType, ...uint32) error 32 | } 33 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/repository/metric.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/cmd/server/palace/internal/biz/bo" 7 | "github.com/aide-family/moon/pkg/palace/model/bizmodel" 8 | ) 9 | 10 | // Metric . 11 | type Metric interface { 12 | // Get 查询指标详情 13 | Get(context.Context, uint32) (*bizmodel.DatasourceMetric, error) 14 | 15 | // GetWithRelation 查询指标详情(关联其他属性) 16 | GetWithRelation(context.Context, uint32) (*bizmodel.DatasourceMetric, error) 17 | 18 | // Delete 删除指标 19 | Delete(context.Context, uint32) error 20 | 21 | // List 查询指标列表 22 | List(context.Context, *bo.QueryMetricListParams) ([]*bizmodel.DatasourceMetric, error) 23 | 24 | // Select 查询指标列表(不关联其他属性) 25 | Select(context.Context, *bo.QueryMetricListParams) ([]*bizmodel.DatasourceMetric, error) 26 | 27 | // Update 更新指标 28 | Update(context.Context, *bo.UpdateMetricParams) error 29 | 30 | // MetricLabelCount 指标标签数量 31 | MetricLabelCount(context.Context, uint32) (uint32, error) 32 | 33 | // CreateMetrics 创建指标 34 | CreateMetrics(context.Context, *bo.CreateMetricParams) error 35 | } 36 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/repository/msg.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/cmd/server/palace/internal/biz/bo" 7 | ) 8 | 9 | // Msg . 10 | type Msg interface { 11 | // Send 发送消息 12 | Send(ctx context.Context, msg *bo.Message) error 13 | } 14 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/repository/oauth_user.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/cmd/server/palace/internal/biz/bo/auth" 7 | "github.com/aide-family/moon/pkg/palace/model" 8 | "github.com/aide-family/moon/pkg/vobj" 9 | ) 10 | 11 | // OAuth . 12 | type OAuth interface { 13 | // OAuthUserFirstOrCreate 获取用户信息, 如果没有则创建 14 | OAuthUserFirstOrCreate(context.Context, auth.IOAuthUser) (*model.SysUser, error) 15 | 16 | // SetEmail 设置电子邮箱 17 | SetEmail(context.Context, string, string) (*model.SysUser, error) 18 | 19 | GetSysUserByOAuthID(context.Context, string, vobj.OAuthAPP) (*model.SysOAuthUser, error) 20 | 21 | SendVerifyEmail(ctx context.Context, email string) error 22 | 23 | CheckVerifyEmailCode(ctx context.Context, email, code string) error 24 | } 25 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/repository/resource.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/cmd/server/palace/internal/biz/bo" 7 | "github.com/aide-family/moon/pkg/palace/imodel" 8 | "github.com/aide-family/moon/pkg/vobj" 9 | ) 10 | 11 | // Resource 资源管理接口 12 | type Resource interface { 13 | // GetByID get resource by id 14 | GetByID(context.Context, uint32) (imodel.IResource, error) 15 | 16 | // CheckPath check resource path 17 | CheckPath(context.Context, string) (imodel.IResource, error) 18 | 19 | // FindByPage find resource by page 20 | FindByPage(context.Context, *bo.QueryResourceListParams) ([]imodel.IResource, error) 21 | 22 | // UpdateStatus update resource status 23 | UpdateStatus(context.Context, vobj.Status, ...uint32) error 24 | 25 | // FindSelectByPage find select resource by page 26 | FindSelectByPage(context.Context, *bo.QueryResourceListParams) ([]imodel.IResource, error) 27 | } 28 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/repository/send_template.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/cmd/server/palace/internal/biz/bo" 7 | "github.com/aide-family/moon/pkg/palace/imodel" 8 | "github.com/aide-family/moon/pkg/vobj" 9 | ) 10 | 11 | type ( 12 | // SendTemplateRepo 告警发送模板仓库接口 13 | SendTemplateRepo interface { 14 | // Create 创建告警发送模板 15 | Create(ctx context.Context, params *bo.CreateSendTemplate) error 16 | // UpdateByID 更新告警发送模板 17 | UpdateByID(ctx context.Context, params *bo.UpdateSendTemplate) error 18 | // DeleteByID 删除告警发送模板 19 | DeleteByID(ctx context.Context, id uint32) error 20 | // FindByPage 分页查询告警发送模板 21 | FindByPage(ctx context.Context, params *bo.QuerySendTemplateListParams) ([]imodel.ISendTemplate, error) 22 | // UpdateStatusByIds 批量更新告警发送模板状态 23 | UpdateStatusByIds(ctx context.Context, status *bo.UpdateSendTemplateStatusParams) error 24 | // GetByID 根据ID查询告警发送模板 25 | GetByID(ctx context.Context, id uint32) (imodel.ISendTemplate, error) 26 | // GetTemplateInfoByName 根据名称查询告警发送模板 27 | GetTemplateInfoByName(ctx context.Context, name string, sendType vobj.AlarmSendType) (imodel.ISendTemplate, error) 28 | } 29 | ) 30 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/repository/statistics.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/cmd/server/palace/internal/biz/bo" 7 | ) 8 | 9 | // Statistics 统计数据 10 | type Statistics interface { 11 | // AddEvents 添加事件 12 | AddEvents(ctx context.Context, events ...*bo.LatestAlarmEvent) error 13 | 14 | // GetLatestEvents 获取最新事件 15 | GetLatestEvents(ctx context.Context, teamID uint32, limit int) ([]*bo.LatestAlarmEvent, error) 16 | 17 | // AddInterventionEvents 添加干预事件 18 | AddInterventionEvents(ctx context.Context, events ...*bo.LatestInterventionEvent) error 19 | 20 | // GetLatestInterventionEvents 获取最新干预事件 21 | GetLatestInterventionEvents(ctx context.Context, teamID uint32, limit int) ([]*bo.LatestInterventionEvent, error) 22 | } 23 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/repository/subscriber.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/cmd/server/palace/internal/biz/bo" 7 | "github.com/aide-family/moon/pkg/palace/model/bizmodel" 8 | ) 9 | 10 | type ( 11 | // SubscriberStrategy 订阅仓库接口 12 | SubscriberStrategy interface { 13 | // UserSubscriberStrategy 用户订阅策略 14 | UserSubscriberStrategy(ctx context.Context, params *bo.SubscriberStrategyParams) error 15 | // UserUnSubscriberStrategy 用户取消订阅策略 16 | UserUnSubscriberStrategy(ctx context.Context, params *bo.UnSubscriberStrategyParams) error 17 | // UserSubscriberStrategyList 用户订阅策略列表 18 | UserSubscriberStrategyList(ctx context.Context, params *bo.QueryUserSubscriberParams) ([]*bizmodel.StrategySubscriber, error) 19 | // StrategySubscriberList 策略订阅用户列表 20 | StrategySubscriberList(ctx context.Context, params *bo.QueryStrategySubscriberParams) ([]*bizmodel.StrategySubscriber, error) 21 | } 22 | ) 23 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/repository/system.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "context" 5 | ) 6 | 7 | // System 系统管理模块 8 | type System interface { 9 | // ResetTeam 重置团队 10 | ResetTeam(ctx context.Context, teamID uint32) error 11 | 12 | // RestoreData 还原数据 13 | RestoreData(ctx context.Context, teamID uint32) error 14 | 15 | // DeleteBackup 删除备份 16 | DeleteBackup(ctx context.Context, teamID uint32) 17 | } 18 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/repository/team_dict.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | type ( 4 | // TeamDict 字典接口 5 | TeamDict interface { 6 | Dict 7 | } 8 | ) 9 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/repository/team_invite.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/cmd/server/palace/internal/biz/bo" 7 | "github.com/aide-family/moon/pkg/palace/model" 8 | ) 9 | 10 | // TeamInvite 团队邀请接口 11 | type TeamInvite interface { 12 | // InviteUser 邀请用户加入团队 13 | InviteUser(ctx context.Context, params *bo.InviteUserParams) (*model.SysTeamInvite, error) 14 | // UpdateInviteStatus 更新邀请状态 15 | UpdateInviteStatus(ctx context.Context, params *bo.UpdateInviteStatusParams) error 16 | // UserInviteList 受邀请列表 17 | UserInviteList(ctx context.Context, params *bo.QueryInviteListParams) ([]*model.SysTeamInvite, error) 18 | // GetInviteUserByUserIDAndType 获取邀请用户信息 19 | GetInviteUserByUserIDAndType(ctx context.Context, params *bo.InviteUserParams) (*model.SysTeamInvite, error) 20 | // GetInviteDetail 获取邀请详情 21 | GetInviteDetail(ctx context.Context, inviteID uint32) (*model.SysTeamInvite, error) 22 | // DeleteInvite 删除邀请 23 | DeleteInvite(ctx context.Context, inviteID uint32) error 24 | // SendInviteEmail 发送邀请邮件 25 | SendInviteEmail(ctx context.Context, params *bo.InviteUserParams, opUser, user *model.SysUser) error 26 | } 27 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/repository/team_menu.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/cmd/server/palace/internal/biz/bo" 7 | "github.com/aide-family/moon/pkg/palace/model/bizmodel" 8 | ) 9 | 10 | // TeamMenu 团队菜单接口 11 | type TeamMenu interface { 12 | GetTeamMenuList(context.Context, *bo.QueryTeamMenuListParams) ([]*bizmodel.SysTeamMenu, error) 13 | } 14 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/repository/team_resource.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | // TeamResource 团队资源管理接口 4 | type TeamResource interface { 5 | Resource 6 | } 7 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/repository/team_send_template.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | type ( 4 | // TeamSendTemplate team send template repo 5 | TeamSendTemplate interface { 6 | SendTemplateRepo 7 | } 8 | ) 9 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/repository/template.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/cmd/server/palace/internal/biz/bo" 7 | "github.com/aide-family/moon/pkg/palace/model" 8 | "github.com/aide-family/moon/pkg/vobj" 9 | ) 10 | 11 | // Template . 12 | type Template interface { 13 | // CreateTemplateStrategy 创建模板策略 14 | CreateTemplateStrategy(ctx context.Context, templateStrategy *bo.CreateTemplateStrategyParams) error 15 | 16 | // UpdateTemplateStrategy 更新模板策略 17 | UpdateTemplateStrategy(ctx context.Context, templateStrategy *bo.UpdateTemplateStrategyParams) error 18 | 19 | // DeleteTemplateStrategy 删除模板策略 20 | DeleteTemplateStrategy(ctx context.Context, id uint32) error 21 | 22 | // GetTemplateStrategy 获取模板策略 23 | GetTemplateStrategy(ctx context.Context, id uint32) (*model.StrategyTemplate, error) 24 | 25 | // ListTemplateStrategy 获取模板策略列表 26 | ListTemplateStrategy(ctx context.Context, params *bo.QueryTemplateStrategyListParams) ([]*model.StrategyTemplate, error) 27 | 28 | // UpdateTemplateStrategyStatus 更新模板策略状态 29 | UpdateTemplateStrategyStatus(ctx context.Context, status vobj.Status, ids ...uint32) error 30 | } 31 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/repository/user_message.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/cmd/server/palace/internal/biz/bo" 7 | "github.com/aide-family/moon/pkg/palace/model" 8 | ) 9 | 10 | // UserMessage 用户消息 11 | type UserMessage interface { 12 | // Create 创建用户消息 13 | Create(context.Context, *model.SysUserMessage) error 14 | 15 | // Delete 删除用户消息 16 | Delete(context.Context, []uint32) error 17 | 18 | // DeleteAll 删除所有用户消息 19 | DeleteAll(context.Context) error 20 | 21 | // List 分页查询用户消息 22 | List(context.Context, *bo.QueryUserMessageListParams) ([]*model.SysUserMessage, error) 23 | 24 | // GetByID 根据ID获取用户消息 25 | GetByID(context.Context, uint32) (*model.SysUserMessage, error) 26 | } 27 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/biz/server_register.go: -------------------------------------------------------------------------------- 1 | package biz 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/api" 7 | "github.com/aide-family/moon/cmd/server/palace/internal/biz/microrepository" 8 | ) 9 | 10 | // NewServerRegisterBiz 创建服务器注册业务对象 11 | func NewServerRegisterBiz(serverRegisterRepository microrepository.ServerRegister) *ServerRegisterBiz { 12 | return &ServerRegisterBiz{ 13 | serverRegisterRepository: serverRegisterRepository, 14 | } 15 | } 16 | 17 | // ServerRegisterBiz 服务器注册业务对象 18 | type ServerRegisterBiz struct { 19 | serverRegisterRepository microrepository.ServerRegister 20 | } 21 | 22 | // Heartbeat 心跳 23 | func (s *ServerRegisterBiz) Heartbeat(ctx context.Context, request *api.HeartbeatRequest) error { 24 | return s.serverRegisterRepository.Heartbeat(ctx, request) 25 | } 26 | 27 | // GetServerList 获取服务器列表 28 | func (s *ServerRegisterBiz) GetServerList(ctx context.Context, request *api.GetServerListRequest) (*api.GetServerListReply, error) { 29 | return s.serverRegisterRepository.GetServerList(ctx, request) 30 | } 31 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/data/README.md: -------------------------------------------------------------------------------- 1 | # Data 2 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/data/microserver/msg.go: -------------------------------------------------------------------------------- 1 | package microserver 2 | 3 | import ( 4 | "context" 5 | 6 | hookapi "github.com/aide-family/moon/api/rabbit/hook" 7 | "github.com/aide-family/moon/cmd/server/palace/internal/biz/bo" 8 | "github.com/aide-family/moon/cmd/server/palace/internal/biz/repository" 9 | "github.com/aide-family/moon/cmd/server/palace/internal/data" 10 | "github.com/aide-family/moon/pkg/util/types" 11 | ) 12 | 13 | // NewMsgRepository 创建消息操作 14 | func NewMsgRepository(cli *data.RabbitConn) repository.Msg { 15 | return &msgRepositoryImpl{cli: cli} 16 | } 17 | 18 | type msgRepositoryImpl struct { 19 | cli *data.RabbitConn 20 | } 21 | 22 | // Send 发送消息 23 | func (m *msgRepositoryImpl) Send(ctx context.Context, msg *bo.Message) error { 24 | dataBytes, _ := types.Marshal(msg.Data) 25 | err := m.cli.SendMsg(ctx, &hookapi.SendMsgRequest{ 26 | Json: string(dataBytes), 27 | Route: "test", 28 | }) 29 | if !types.IsNil(err) { 30 | return err 31 | } 32 | return nil 33 | } 34 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/data/microserver/register.go: -------------------------------------------------------------------------------- 1 | package microserver 2 | 3 | import ( 4 | "github.com/google/wire" 5 | ) 6 | 7 | // ProviderSetRPCRepoImpl rpc repo impl provider 8 | var ProviderSetRPCRepoImpl = wire.NewSet( 9 | NewDatasourceMetricRepository, 10 | NewMsgRepository, 11 | NewStrategyRepository, 12 | NewServerRegisterRepository, 13 | NewSendAlertRepository, 14 | ) 15 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/data/microserver/strategy.go: -------------------------------------------------------------------------------- 1 | package microserver 2 | 3 | import ( 4 | "context" 5 | 6 | strategyapi "github.com/aide-family/moon/api/houyi/strategy" 7 | "github.com/aide-family/moon/cmd/server/palace/internal/biz/microrepository" 8 | "github.com/aide-family/moon/cmd/server/palace/internal/data" 9 | "github.com/go-kratos/kratos/v2/log" 10 | ) 11 | 12 | // NewStrategyRepository 创建策略仓库 13 | func NewStrategyRepository(data *data.Data, houyiClient *data.HouYiConn) microrepository.Strategy { 14 | return &strategyRepositoryImpl{data: data, houyiClient: houyiClient} 15 | } 16 | 17 | type strategyRepositoryImpl struct { 18 | data *data.Data 19 | 20 | houyiClient *data.HouYiConn 21 | } 22 | 23 | func (s *strategyRepositoryImpl) Push(ctx context.Context, strategies *strategyapi.PushStrategyRequest) error { 24 | if strategies == nil { 25 | return nil 26 | } 27 | strategyReply, err := s.houyiClient.PushStrategy(ctx, strategies) 28 | if err != nil { 29 | return err 30 | } 31 | log.Debugw("strategyReply", strategyReply) 32 | return nil 33 | } 34 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/data/repoimpl/lock.go: -------------------------------------------------------------------------------- 1 | package repoimpl 2 | 3 | import ( 4 | "context" 5 | "time" 6 | 7 | "github.com/aide-family/moon/cmd/server/palace/internal/biz/repository" 8 | "github.com/aide-family/moon/cmd/server/palace/internal/data" 9 | "github.com/aide-family/moon/pkg/merr" 10 | ) 11 | 12 | // NewLockRepository 创建全局锁 13 | func NewLockRepository(data *data.Data) repository.Lock { 14 | return &lockRepositoryImpl{data: data} 15 | } 16 | 17 | type lockRepositoryImpl struct { 18 | data *data.Data 19 | } 20 | 21 | func (l *lockRepositoryImpl) Lock(ctx context.Context, key string, expire time.Duration) error { 22 | locked, err := l.data.GetCacher().Client().SetNX(ctx, key, key, expire).Result() 23 | if err != nil { 24 | return err 25 | } 26 | // 判断是否存在 27 | if !locked { 28 | return merr.ErrorI18nToastDatasourceSyncing(ctx) 29 | } 30 | return nil 31 | } 32 | 33 | func (l *lockRepositoryImpl) UnLock(ctx context.Context, key string) error { 34 | return l.data.GetCacher().Client().Del(ctx, key).Err() 35 | } 36 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/data/repoimpl/team_menu.go: -------------------------------------------------------------------------------- 1 | package repoimpl 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/cmd/server/palace/internal/biz/bo" 7 | "github.com/aide-family/moon/cmd/server/palace/internal/biz/repository" 8 | "github.com/aide-family/moon/cmd/server/palace/internal/data" 9 | "github.com/aide-family/moon/pkg/palace/model/bizmodel" 10 | "github.com/aide-family/moon/pkg/palace/model/bizmodel/bizquery" 11 | "github.com/aide-family/moon/pkg/util/types" 12 | ) 13 | 14 | // NewTeamMenuRepository 创建团队菜单仓库 15 | func NewTeamMenuRepository(data *data.Data) repository.TeamMenu { 16 | return &teamMenuRepositoryImpl{ 17 | data: data, 18 | } 19 | } 20 | 21 | type teamMenuRepositoryImpl struct { 22 | data *data.Data 23 | } 24 | 25 | func (l *teamMenuRepositoryImpl) GetTeamMenuList(ctx context.Context, params *bo.QueryTeamMenuListParams) ([]*bizmodel.SysTeamMenu, error) { 26 | bizDB, err := l.data.GetBizGormDB(params.TeamID) 27 | if !types.IsNil(err) { 28 | return nil, err 29 | } 30 | bizQuery := bizquery.Use(bizDB) 31 | return bizQuery.SysTeamMenu.WithContext(ctx).Find() 32 | } 33 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/data/runtime/cache/entry.go: -------------------------------------------------------------------------------- 1 | package cache 2 | 3 | import ( 4 | "context" 5 | 6 | "k8s.io/client-go/tools/cache" 7 | ) 8 | 9 | type entry struct { 10 | indexer cache.Indexer 11 | reader Reader 12 | writer Writer 13 | } 14 | 15 | func (e *entry) Get(ctx context.Context, key string, out any) error { 16 | return e.reader.Get(ctx, key, out) 17 | } 18 | 19 | func (e *entry) List(ctx context.Context, out any) error { 20 | return e.reader.List(ctx, out) 21 | } 22 | 23 | func (e *entry) AddIndexers(indexers cache.Indexers) error { 24 | return e.indexer.AddIndexers(indexers) 25 | } 26 | 27 | func (e *entry) GetIndexer() cache.Indexer { 28 | return e.indexer 29 | } 30 | 31 | func (e *entry) Add(ctx context.Context, objects any) error { 32 | return e.writer.Add(ctx, objects) 33 | } 34 | 35 | func (e *entry) Replace(ctx context.Context, objects any) error { 36 | return e.writer.Replace(ctx, objects) 37 | } 38 | 39 | func (e *entry) Update(ctx context.Context, object any) error { 40 | return e.writer.Update(ctx, object) 41 | } 42 | 43 | func (e *entry) Delete(ctx context.Context, object any) error { 44 | return e.writer.Delete(ctx, object) 45 | } 46 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/data/runtime/cache/init_test.go: -------------------------------------------------------------------------------- 1 | package cache 2 | 3 | import ( 4 | "github.com/aide-family/moon/cmd/server/palace/internal/data/runtime" 5 | "k8s.io/client-go/tools/cache" 6 | ) 7 | 8 | type TestStruct struct { 9 | Field1 string 10 | Field2 int 11 | } 12 | 13 | func (t *TestStruct) KeyFunc(obj interface{}) (string, error) { 14 | return obj.(*TestStruct).Field1, nil 15 | } 16 | 17 | var ts = &TestStruct{} 18 | 19 | func NewMockIndexer() cache.Indexer { 20 | return cache.NewIndexer(ts.KeyFunc, cache.Indexers{}) 21 | } 22 | 23 | var testScheme = runtime.NewScheme() 24 | 25 | func init() { 26 | testScheme.AddKnownTypes(&TestStruct{}) 27 | } 28 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/data/runtime/interface.go: -------------------------------------------------------------------------------- 1 | package runtime 2 | 3 | import "context" 4 | 5 | // Reader 读取器 6 | type Reader interface { 7 | // Get 获取数据 8 | Get(ctx context.Context, key string, out any) error 9 | // List 获取数据列表 10 | List(ctx context.Context, out any) error 11 | } 12 | 13 | // Writer 写入器 14 | type Writer interface { 15 | // Create 创建数据 16 | Create(ctx context.Context, object any) error 17 | // Update 更新数据 18 | Update(ctx context.Context, object any) error 19 | // Delete 删除数据 20 | Delete(ctx context.Context, object any) error 21 | } 22 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/data/sendtemplate/send_dingtalk.tpl: -------------------------------------------------------------------------------- 1 | {{- $status := .status -}} 2 | {{- $labels := .labels -}} 3 | {{- $annotations := .annotations -}} 4 | 5 | { 6 | "msgtype": "markdown", 7 | "markdown": { 8 | "title": "平台状态通知", 9 | "text": "### {{if eq $status `resolved`}}✅ 告警已恢复{{else}}🚨 紧急告警通知{{end}}\n\n \n**时间**: `{{ .startsAt }}` 至 `{{ .endsAt }}` \n\n
\n\n**摘要**: \n`{{ $annotations.summary }}` \n\n**描述**: \n`{{ $annotations.description }}` \n\n
\n\n**标签**: \n- **数据源 ID**: {{ index $labels "__moon__datasource_id__" }} \n- **数据源 URL**: [链接]({{ index $labels "__moon__datasource_url__" }}) \n- **级别 ID**: {{ index $labels "__moon__level_id__" }} \n- **策略 ID**: {{ index $labels "__moon__strategy_id__" }} \n- **团队 ID**: {{ index $labels "__moon__team_id__" }} \n- **实例**: `{{ index $labels "instance" }}` \n- **IP**: `{{ index $labels "ip" }}` \n- **作业**: `{{ index $labels "job" }}` \n\n
\n\n请根据以上信息进行后续处理!" 10 | } 11 | } -------------------------------------------------------------------------------- /cmd/server/palace/internal/data/sendtemplate/send_email.html: -------------------------------------------------------------------------------- 1 |

监控告警

2 |

{{ .annotations.summary }}

3 |

{{ .annotations.description }}

4 |

时间: {{ .startsAt }} 至 {{ .endsAt }}

-------------------------------------------------------------------------------- /cmd/server/palace/internal/data/sendtemplate/send_wechat.json: -------------------------------------------------------------------------------- 1 | { 2 | "msgtype": "markdown", 3 | "markdown": { 4 | "content": "### {{if eq .status `resolved`}}✅ 告警已恢复{{else}}🚨 紧急告警通知{{end}}\n\n {{ .annotations }}" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/palaceconf/.gitignore: -------------------------------------------------------------------------------- 1 | *.*.go -------------------------------------------------------------------------------- /cmd/server/palace/internal/server/grpc.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | import ( 4 | "github.com/aide-family/moon/cmd/server/palace/internal/palaceconf" 5 | "github.com/aide-family/moon/pkg/helper/middleware" 6 | "github.com/aide-family/moon/pkg/plugin/mlog" 7 | 8 | "github.com/bufbuild/protovalidate-go" 9 | "github.com/go-kratos/kratos/v2/log" 10 | "github.com/go-kratos/kratos/v2/middleware/recovery" 11 | "github.com/go-kratos/kratos/v2/middleware/tracing" 12 | "github.com/go-kratos/kratos/v2/transport/grpc" 13 | ) 14 | 15 | // NewGRPCServer new a gRPC server. 16 | func NewGRPCServer(bc *palaceconf.Bootstrap) *grpc.Server { 17 | c := bc.GetGrpc() 18 | opts := []grpc.ServerOption{ 19 | grpc.Middleware( 20 | recovery.Recovery(recovery.WithHandler(mlog.RecoveryHandle)), 21 | tracing.Server(), 22 | middleware.Logging(log.GetLogger()), 23 | middleware.Validate(protovalidate.WithFailFast(false)), 24 | ), 25 | } 26 | if c.GetNetwork() != "" { 27 | opts = append(opts, grpc.Network(c.GetNetwork())) 28 | } 29 | if c.GetAddr() != "" { 30 | opts = append(opts, grpc.Address(c.GetAddr())) 31 | } 32 | if c.GetTimeout() != nil { 33 | opts = append(opts, grpc.Timeout(c.GetTimeout().AsDuration())) 34 | } 35 | srv := grpc.NewServer(opts...) 36 | 37 | return srv 38 | } 39 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/service/README.md: -------------------------------------------------------------------------------- 1 | # Service 2 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/service/builder/pagination.go: -------------------------------------------------------------------------------- 1 | package builder 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/api" 7 | "github.com/aide-family/moon/pkg/util/types" 8 | ) 9 | 10 | var _ IPaginationModuleBuilder = (*paginationModuleBuilder)(nil) 11 | 12 | type ( 13 | // IPaginationModuleBuilder 分页模块构造器 14 | IPaginationModuleBuilder interface { 15 | // ToBo 转换为业务对象 16 | ToBo(*api.PaginationReq) types.Pagination 17 | // ToAPI 转换为API对象 18 | ToAPI(types.Pagination) *api.PaginationReply 19 | } 20 | 21 | paginationModuleBuilder struct { 22 | ctx context.Context 23 | } 24 | ) 25 | 26 | func (p *paginationModuleBuilder) ToBo(req *api.PaginationReq) types.Pagination { 27 | return types.NewPagination(req) 28 | } 29 | 30 | func (p *paginationModuleBuilder) ToAPI(pagination types.Pagination) *api.PaginationReply { 31 | if types.IsNil(pagination) { 32 | return nil 33 | } 34 | return &api.PaginationReply{ 35 | PageNum: pagination.GetPageNum(), 36 | PageSize: pagination.GetPageSize(), 37 | Total: pagination.GetTotal(), 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/service/health.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/api" 7 | "github.com/aide-family/moon/cmd/server/palace/internal/data" 8 | "github.com/aide-family/moon/pkg/env" 9 | ) 10 | 11 | // HealthService 健康检查 12 | type HealthService struct { 13 | api.UnimplementedHealthServer 14 | 15 | houyiSrv *data.HouYiConn 16 | } 17 | 18 | // NewHealthService 创建健康检查服务 19 | func NewHealthService(houyiSrv *data.HouYiConn) *HealthService { 20 | return &HealthService{ 21 | houyiSrv: houyiSrv, 22 | } 23 | } 24 | 25 | // Check 检查 26 | func (s *HealthService) Check(ctx context.Context, req *api.CheckRequest) (*api.CheckReply, error) { 27 | //if _, err := s.houyiSrv.Health(ctx, req); err != nil { 28 | // log.Warnw("houyiSrv", err) 29 | //} 30 | return &api.CheckReply{Healthy: true, Version: env.Version()}, nil 31 | } 32 | -------------------------------------------------------------------------------- /cmd/server/palace/internal/service/system/system.go: -------------------------------------------------------------------------------- 1 | package system 2 | 3 | import ( 4 | "context" 5 | 6 | pb "github.com/aide-family/moon/api/admin/system" 7 | "github.com/aide-family/moon/cmd/server/palace/internal/biz" 8 | ) 9 | 10 | // Service 系统操作服务 11 | type Service struct { 12 | pb.UnimplementedSystemServer 13 | 14 | systemBiz *biz.SystemBiz 15 | } 16 | 17 | // NewSystemService 创建系统操作服务 18 | func NewSystemService(systemBiz *biz.SystemBiz) *Service { 19 | return &Service{systemBiz: systemBiz} 20 | } 21 | 22 | // ResetTeam 重置团队 23 | func (s *Service) ResetTeam(ctx context.Context, req *pb.ResetTeamRequest) (*pb.ResetTeamReply, error) { 24 | if err := s.systemBiz.ResetTeam(ctx, req.GetTeamID()); err != nil { 25 | return nil, err 26 | } 27 | return &pb.ResetTeamReply{}, nil 28 | } 29 | -------------------------------------------------------------------------------- /cmd/server/palace/palace/cmd.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | 6 | _ "go.uber.org/automaxprocs" 7 | 8 | "github.com/aide-family/moon/pkg/helper" 9 | 10 | "github.com/aide-family/moon/cmd/server/palace" 11 | "github.com/aide-family/moon/pkg/env" 12 | ) 13 | 14 | // go build -ldflags "-X main.Version=x.y.z" 15 | var ( 16 | // flagconf is the config flag. 17 | flagconf string 18 | 19 | // configType is the config file type. 20 | configType string 21 | 22 | // Version is the version of the compiled software. 23 | Version string 24 | 25 | // pprofAddress is the pprof address. 26 | pprofAddress string 27 | ) 28 | 29 | func init() { 30 | flag.StringVar(&flagconf, "c", "../configs", "config path, eg: -c ./configs") 31 | flag.StringVar(&configType, "config_ext", "yaml", "config file ext name, eg: -config_ext yaml") 32 | flag.StringVar(&pprofAddress, "pprof_address", "", "pprof address, eg: -pprof_address 0.0.0.0:6060") 33 | } 34 | 35 | func main() { 36 | flag.Parse() 37 | env.SetVersion(Version) 38 | helper.Pprof(pprofAddress) 39 | palace.Run(flagconf, configType) 40 | } 41 | -------------------------------------------------------------------------------- /cmd/server/palace/wire.go: -------------------------------------------------------------------------------- 1 | //go:build wireinject 2 | // +build wireinject 3 | 4 | // The build tag makes sure the stub is not built in the final build. 5 | 6 | package palace 7 | 8 | import ( 9 | "github.com/aide-family/moon/cmd/server/palace/internal/biz" 10 | "github.com/aide-family/moon/cmd/server/palace/internal/data" 11 | "github.com/aide-family/moon/cmd/server/palace/internal/data/microserver" 12 | "github.com/aide-family/moon/cmd/server/palace/internal/data/repoimpl" 13 | "github.com/aide-family/moon/cmd/server/palace/internal/palaceconf" 14 | "github.com/aide-family/moon/cmd/server/palace/internal/server" 15 | "github.com/aide-family/moon/cmd/server/palace/internal/service" 16 | "github.com/go-kratos/kratos/v2" 17 | "github.com/go-kratos/kratos/v2/log" 18 | "github.com/google/wire" 19 | ) 20 | 21 | // wireApp init kratos application. 22 | func wireApp(*palaceconf.Bootstrap, log.Logger) (*kratos.App, func(), error) { 23 | panic(wire.Build( 24 | server.ProviderSetServer, 25 | data.ProviderSetData, 26 | repoimpl.ProviderSetRepoImpl, 27 | biz.ProviderSetBiz, 28 | service.ProviderSetService, 29 | microserver.ProviderSetRPCRepoImpl, 30 | data.ProviderSetRPCConn, 31 | newApp, 32 | )) 33 | } 34 | -------------------------------------------------------------------------------- /cmd/server/rabbit/configs/.gitignore: -------------------------------------------------------------------------------- 1 | *_config.yaml 2 | local.yaml -------------------------------------------------------------------------------- /cmd/server/rabbit/internal/biz/README.md: -------------------------------------------------------------------------------- 1 | # Biz 2 | -------------------------------------------------------------------------------- /cmd/server/rabbit/internal/biz/biz.go: -------------------------------------------------------------------------------- 1 | package biz 2 | 3 | import "github.com/google/wire" 4 | 5 | // ProviderSetBiz is biz providers. 6 | var ProviderSetBiz = wire.NewSet( 7 | NewMsgBiz, 8 | NewConfigBiz, 9 | NewHeartbeatBiz, 10 | ) 11 | -------------------------------------------------------------------------------- /cmd/server/rabbit/internal/biz/bo/config.go: -------------------------------------------------------------------------------- 1 | package bo 2 | 3 | import ( 4 | "github.com/aide-family/moon/pkg/conf" 5 | "github.com/aide-family/moon/pkg/util/types" 6 | ) 7 | 8 | // CacheConfigParams 缓存配置参数 9 | type CacheConfigParams struct { 10 | Receivers map[string]*conf.Receiver `json:"receivers"` 11 | Templates map[string]string `json:"templates"` 12 | } 13 | 14 | // String 字符串化 15 | func (c *CacheConfigParams) String() string { 16 | bs, _ := types.Marshal(c) 17 | return string(bs) 18 | } 19 | -------------------------------------------------------------------------------- /cmd/server/rabbit/internal/biz/bo/msg.go: -------------------------------------------------------------------------------- 1 | package bo 2 | 3 | import ( 4 | "github.com/aide-family/moon/pkg/notify" 5 | "github.com/aide-family/moon/pkg/util/types" 6 | "github.com/aide-family/moon/pkg/vobj" 7 | "github.com/aide-family/moon/pkg/watch" 8 | ) 9 | 10 | var _ watch.Indexer = (*SendMsgParams)(nil) 11 | 12 | // SendMsgParams 发送消息请求参数 13 | type SendMsgParams struct { 14 | Route string 15 | Data []byte 16 | RequestID string 17 | } 18 | 19 | // String 转换为字符串 20 | func (s *SendMsgParams) String() string { 21 | return types.TextJoin("rabbit:", s.Route, ":", s.RequestID) 22 | } 23 | 24 | // Key 获取消息的键 25 | func (s *SendMsgParams) Key(app notify.Notify) string { 26 | return types.TextJoin("rabbit:", app.Type(), ":", s.Route, ":", types.MD5(types.TextJoin(s.RequestID, app.Hash()))) 27 | } 28 | 29 | // Index 获取消息的索引 30 | func (s *SendMsgParams) Index() string { 31 | return s.RequestID 32 | } 33 | 34 | // Message 接收到的消息 35 | func (s *SendMsgParams) Message() *watch.Message { 36 | return watch.NewMessage(s, vobj.TopicAlertMsg) 37 | } 38 | -------------------------------------------------------------------------------- /cmd/server/rabbit/internal/biz/heartbeat.go: -------------------------------------------------------------------------------- 1 | package biz 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/api" 7 | "github.com/aide-family/moon/cmd/server/rabbit/internal/biz/repository" 8 | ) 9 | 10 | // NewHeartbeatBiz 创建心跳包业务对象 11 | func NewHeartbeatBiz(heartbeatRepository repository.Heartbeat) *HeartbeatBiz { 12 | return &HeartbeatBiz{ 13 | heartbeatRepository: heartbeatRepository, 14 | } 15 | } 16 | 17 | // HeartbeatBiz 心跳包业务对象 18 | type HeartbeatBiz struct { 19 | heartbeatRepository repository.Heartbeat 20 | } 21 | 22 | // Heartbeat 心跳包 23 | func (b *HeartbeatBiz) Heartbeat(ctx context.Context, in *api.HeartbeatRequest) error { 24 | return b.heartbeatRepository.Heartbeat(ctx, in) 25 | } 26 | -------------------------------------------------------------------------------- /cmd/server/rabbit/internal/biz/repository/cache_repo.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "github.com/aide-family/moon/pkg/plugin/cache" 5 | ) 6 | 7 | // CacheRepo 缓存仓库 8 | type CacheRepo interface { 9 | // Cacher 获取缓存实例 10 | Cacher() cache.ICacher 11 | } 12 | -------------------------------------------------------------------------------- /cmd/server/rabbit/internal/biz/repository/heartbeat.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/api" 7 | ) 8 | 9 | // Heartbeat . 10 | type Heartbeat interface { 11 | // Heartbeat 心跳包 12 | Heartbeat(ctx context.Context, in *api.HeartbeatRequest) error 13 | } 14 | -------------------------------------------------------------------------------- /cmd/server/rabbit/internal/data/README.md: -------------------------------------------------------------------------------- 1 | # Data 2 | -------------------------------------------------------------------------------- /cmd/server/rabbit/internal/data/microserver/register.go: -------------------------------------------------------------------------------- 1 | package microserver 2 | 3 | import ( 4 | "github.com/google/wire" 5 | ) 6 | 7 | // ProviderSetRPCConn wire set 8 | var ProviderSetRPCConn = wire.NewSet( 9 | NewPalaceConn, 10 | ) 11 | -------------------------------------------------------------------------------- /cmd/server/rabbit/internal/data/repoimpl/cache.go: -------------------------------------------------------------------------------- 1 | package repoimpl 2 | 3 | import ( 4 | "github.com/aide-family/moon/cmd/server/rabbit/internal/biz/repository" 5 | "github.com/aide-family/moon/cmd/server/rabbit/internal/data" 6 | "github.com/aide-family/moon/pkg/plugin/cache" 7 | ) 8 | 9 | // NewCacheRepo 创建缓存操作 10 | func NewCacheRepo(data *data.Data) repository.CacheRepo { 11 | return &cacheRepoImpl{data: data} 12 | } 13 | 14 | type cacheRepoImpl struct { 15 | data *data.Data 16 | } 17 | 18 | func (l *cacheRepoImpl) Cacher() cache.ICacher { 19 | return l.data.GetCacher() 20 | } 21 | -------------------------------------------------------------------------------- /cmd/server/rabbit/internal/data/repoimpl/heartbeat.go: -------------------------------------------------------------------------------- 1 | package repoimpl 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/api" 7 | "github.com/aide-family/moon/cmd/server/rabbit/internal/biz/repository" 8 | "github.com/aide-family/moon/cmd/server/rabbit/internal/data/microserver" 9 | ) 10 | 11 | // NewHeartbeatRepository 初始化心跳存储层 12 | func NewHeartbeatRepository(palaceConn *microserver.PalaceConn) repository.Heartbeat { 13 | return &heartbeatRepositoryImpl{ 14 | palaceConn: palaceConn, 15 | } 16 | } 17 | 18 | type heartbeatRepositoryImpl struct { 19 | palaceConn *microserver.PalaceConn 20 | } 21 | 22 | func (h *heartbeatRepositoryImpl) Heartbeat(ctx context.Context, in *api.HeartbeatRequest) error { 23 | _, err := h.palaceConn.Heartbeat(ctx, in) 24 | 25 | return err 26 | } 27 | -------------------------------------------------------------------------------- /cmd/server/rabbit/internal/data/repoimpl/register.go: -------------------------------------------------------------------------------- 1 | package repoimpl 2 | 3 | import ( 4 | "github.com/google/wire" 5 | ) 6 | 7 | // ProviderSetRepoImpl wire set 8 | var ProviderSetRepoImpl = wire.NewSet( 9 | NewCacheRepo, 10 | NewHeartbeatRepository, 11 | ) 12 | -------------------------------------------------------------------------------- /cmd/server/rabbit/internal/rabbitconf/.gitignore: -------------------------------------------------------------------------------- 1 | *.*.go -------------------------------------------------------------------------------- /cmd/server/rabbit/internal/rabbitconf/conf.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package moon.cmd.server.demo.internal.rabbitconf; 4 | 5 | import "conf/conf.proto"; 6 | 7 | option go_package = "github.com/aide-family/moon/cmd/server/rabbit/internal/rabbitconf;rabbitconf"; 8 | 9 | message Bootstrap { 10 | pkg.conf.Server server = 1; 11 | string env = 3; 12 | // 根据路由匹配具体的发送对象 13 | map receivers = 4; 14 | map templates = 5; 15 | // 全局邮件配置 16 | pkg.conf.EmailConfig global_email_config = 6; 17 | // 服务发现配置, 如果配置了服务发现,endpoint则会被当作服务发现地址, 没有配置直接当作服务地址 18 | pkg.conf.Discovery discovery = 7; 19 | pkg.conf.HTTPServer http = 8; 20 | pkg.conf.GRPCServer grpc = 9; 21 | pkg.conf.Cache cache = 10; 22 | repeated uint32 teams = 11; 23 | bool dependPalace = 12; 24 | // 月宫代理服务 25 | pkg.conf.MicroServer palace_server = 13; 26 | // metrics配置 27 | string metricsToken = 19; 28 | // log配置 29 | pkg.conf.Log log = 20; 30 | } 31 | 32 | 33 | -------------------------------------------------------------------------------- /cmd/server/rabbit/internal/server/consumer.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | import ( 4 | "context" 5 | "time" 6 | 7 | "github.com/aide-family/moon/cmd/server/rabbit/internal/biz/bo" 8 | "github.com/aide-family/moon/cmd/server/rabbit/internal/data" 9 | "github.com/aide-family/moon/cmd/server/rabbit/internal/rabbitconf" 10 | "github.com/aide-family/moon/cmd/server/rabbit/internal/service" 11 | "github.com/aide-family/moon/pkg/vobj" 12 | "github.com/aide-family/moon/pkg/watch" 13 | ) 14 | 15 | func newConsumer(_ *rabbitconf.Bootstrap, data *data.Data, sendService *service.HookService) *watch.Watcher { 16 | opts := []watch.WatcherOption{ 17 | watch.WithWatcherStorage(data.GetWatcherStorage()), 18 | watch.WithWatcherQueue(data.GetWatcherQueue()), 19 | watch.WithWatcherHandler(watch.NewDefaultHandler( 20 | watch.WithDefaultHandlerTopicHandle(vobj.TopicAlertMsg, func(ctx context.Context, msg *watch.Message) error { 21 | msgParams, ok := msg.GetData().(*bo.SendMsgParams) 22 | if !ok { 23 | return nil 24 | } 25 | time.Sleep(time.Second * 1) 26 | return sendService.Send(ctx, msgParams) 27 | }), 28 | )), 29 | } 30 | return watch.NewWatcher("notice worker", opts...) 31 | } 32 | -------------------------------------------------------------------------------- /cmd/server/rabbit/internal/server/grpc.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | import ( 4 | "github.com/aide-family/moon/cmd/server/rabbit/internal/rabbitconf" 5 | "github.com/aide-family/moon/pkg/helper/middleware" 6 | "github.com/aide-family/moon/pkg/plugin/mlog" 7 | "github.com/bufbuild/protovalidate-go" 8 | "github.com/go-kratos/kratos/v2/log" 9 | "github.com/go-kratos/kratos/v2/middleware/recovery" 10 | "github.com/go-kratos/kratos/v2/transport/grpc" 11 | ) 12 | 13 | // NewGRPCServer new a gRPC server. 14 | func NewGRPCServer(bc *rabbitconf.Bootstrap) *grpc.Server { 15 | c := bc.GetGrpc() 16 | opts := []grpc.ServerOption{ 17 | grpc.Middleware( 18 | recovery.Recovery(recovery.WithHandler(mlog.RecoveryHandle)), 19 | middleware.Logging(log.GetLogger()), 20 | middleware.Validate(protovalidate.WithFailFast(false)), 21 | ), 22 | } 23 | if c.GetNetwork() != "" { 24 | opts = append(opts, grpc.Network(c.GetNetwork())) 25 | } 26 | if c.GetAddr() != "" { 27 | opts = append(opts, grpc.Address(c.GetAddr())) 28 | } 29 | if c.GetTimeout() != nil { 30 | opts = append(opts, grpc.Timeout(c.GetTimeout().AsDuration())) 31 | } 32 | srv := grpc.NewServer(opts...) 33 | 34 | return srv 35 | } 36 | -------------------------------------------------------------------------------- /cmd/server/rabbit/internal/service/README.md: -------------------------------------------------------------------------------- 1 | # Service 2 | -------------------------------------------------------------------------------- /cmd/server/rabbit/internal/service/config.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "context" 5 | "time" 6 | 7 | pushapi "github.com/aide-family/moon/api/rabbit/push" 8 | "github.com/aide-family/moon/cmd/server/rabbit/internal/biz" 9 | "github.com/aide-family/moon/cmd/server/rabbit/internal/biz/bo" 10 | "github.com/aide-family/moon/pkg/util/types" 11 | ) 12 | 13 | // ConfigService 配置服务 14 | type ConfigService struct { 15 | pushapi.UnimplementedConfigServer 16 | 17 | configBiz *biz.ConfigBiz 18 | } 19 | 20 | // NewConfigService 创建配置服务 21 | func NewConfigService(configBiz *biz.ConfigBiz) *ConfigService { 22 | return &ConfigService{ 23 | configBiz: configBiz, 24 | } 25 | } 26 | 27 | // NotifyObject 配置模板同步 28 | func (s *ConfigService) NotifyObject(ctx context.Context, req *pushapi.NotifyObjectRequest) (*pushapi.NotifyObjectReply, error) { 29 | s.configBiz.CacheConfig(ctx, &bo.CacheConfigParams{ 30 | Receivers: req.GetReceivers(), 31 | Templates: req.GetTemplates(), 32 | }) 33 | return &pushapi.NotifyObjectReply{Msg: "ok", Time: types.NewTime(time.Now()).String()}, nil 34 | } 35 | 36 | // LoadNotifyObject 加载配置 37 | func (s *ConfigService) LoadNotifyObject(ctx context.Context) error { 38 | s.configBiz.LoadConfig(ctx) 39 | return nil 40 | } 41 | -------------------------------------------------------------------------------- /cmd/server/rabbit/internal/service/health.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/api" 7 | "github.com/aide-family/moon/cmd/server/rabbit/internal/biz" 8 | "github.com/aide-family/moon/pkg/env" 9 | ) 10 | 11 | // HealthService 健康检查 12 | type HealthService struct { 13 | api.UnimplementedHealthServer 14 | 15 | heartbeatBiz *biz.HeartbeatBiz 16 | } 17 | 18 | // NewHealthService 创建健康检查服务 19 | func NewHealthService(heartbeatBiz *biz.HeartbeatBiz) *HealthService { 20 | return &HealthService{ 21 | heartbeatBiz: heartbeatBiz, 22 | } 23 | } 24 | 25 | // Check 检查 26 | func (s *HealthService) Check(_ context.Context, _ *api.CheckRequest) (*api.CheckReply, error) { 27 | return &api.CheckReply{Healthy: true, Version: env.Version()}, nil 28 | } 29 | 30 | // Heartbeat 心跳包 31 | func (s *HealthService) Heartbeat(ctx context.Context, in *api.HeartbeatRequest) error { 32 | return s.heartbeatBiz.Heartbeat(ctx, in) 33 | } 34 | -------------------------------------------------------------------------------- /cmd/server/rabbit/internal/service/service.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "github.com/google/wire" 5 | ) 6 | 7 | // ProviderSetService is service providers. 8 | var ProviderSetService = wire.NewSet( 9 | NewConfigService, 10 | NewHookService, 11 | NewHealthService, 12 | ) 13 | -------------------------------------------------------------------------------- /cmd/server/rabbit/rabbit/cmd.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | 6 | _ "go.uber.org/automaxprocs" 7 | 8 | "github.com/aide-family/moon/pkg/helper" 9 | 10 | "github.com/aide-family/moon/cmd/server/rabbit" 11 | "github.com/aide-family/moon/pkg/env" 12 | ) 13 | 14 | // go build -ldflags "-X main.Version=x.y.z" 15 | var ( 16 | // flagconf is the config flag. 17 | flagconf string 18 | 19 | // configType is the config file type. 20 | configType string 21 | 22 | // Version is the version of the compiled software. 23 | Version string 24 | 25 | // pprofAddress is the pprof address. 26 | pprofAddress string 27 | ) 28 | 29 | func init() { 30 | flag.StringVar(&flagconf, "c", "../configs", "config path, eg: -c ./configs") 31 | flag.StringVar(&configType, "config_ext", "yaml", "config file ext name, eg: -config_ext yaml") 32 | flag.StringVar(&pprofAddress, "pprof_address", "", "pprof address, eg: -pprof_address 0.0.0.0:6060") 33 | } 34 | 35 | func main() { 36 | flag.Parse() 37 | env.SetVersion(Version) 38 | helper.Pprof(pprofAddress) 39 | rabbit.Run(flagconf, configType) 40 | } 41 | -------------------------------------------------------------------------------- /cmd/server/rabbit/wire.go: -------------------------------------------------------------------------------- 1 | //go:build wireinject 2 | // +build wireinject 3 | 4 | // The build tag makes sure the stub is not built in the final build. 5 | 6 | package rabbit 7 | 8 | import ( 9 | "github.com/aide-family/moon/cmd/server/rabbit/internal/biz" 10 | "github.com/aide-family/moon/cmd/server/rabbit/internal/data" 11 | "github.com/aide-family/moon/cmd/server/rabbit/internal/data/microserver" 12 | "github.com/aide-family/moon/cmd/server/rabbit/internal/data/repoimpl" 13 | "github.com/aide-family/moon/cmd/server/rabbit/internal/rabbitconf" 14 | "github.com/aide-family/moon/cmd/server/rabbit/internal/server" 15 | "github.com/aide-family/moon/cmd/server/rabbit/internal/service" 16 | "github.com/go-kratos/kratos/v2" 17 | "github.com/go-kratos/kratos/v2/log" 18 | "github.com/google/wire" 19 | ) 20 | 21 | // wireApp init kratos application. 22 | func wireApp(*rabbitconf.Bootstrap, log.Logger) (*kratos.App, func(), error) { 23 | panic(wire.Build( 24 | server.ProviderSetServer, 25 | data.ProviderSetData, 26 | microserver.ProviderSetRPCConn, 27 | repoimpl.ProviderSetRepoImpl, 28 | biz.ProviderSetBiz, 29 | service.ProviderSetService, 30 | newApp, 31 | )) 32 | } 33 | -------------------------------------------------------------------------------- /deploy/docker/moon/README.md: -------------------------------------------------------------------------------- 1 | # 使用前请配置配置文件中的各个连接信息、oauth2配置、email配置等 -------------------------------------------------------------------------------- /deploy/docker/moon/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: "3.8" 2 | services: 3 | palace: 4 | image: docker.cloudimages.asia/aidemoonio/palace:latest 5 | container_name: moon_palace 6 | ports: 7 | - "8000:8000" 8 | - "9000:9000" 9 | volumes: 10 | - ./palace:/data/conf 11 | 12 | houyi: 13 | image: docker.cloudimages.asia/aidemoonio/houyi:latest 14 | container_name: moon_houyi 15 | ports: 16 | - "8001:8001" 17 | - "9001:9001" 18 | volumes: 19 | - ./houyi:/data/conf 20 | 21 | rabbit: 22 | image: docker.cloudimages.asia/aidemoonio/rabbit:latest 23 | container_name: moon_rabbit 24 | ports: 25 | - "8002:8002" 26 | - "9002:9002" 27 | volumes: 28 | - ./rabbit:/data/conf 29 | 30 | # 如需使用域名,请将web和palace解析到统一域名下,/api解析到palace 31 | web: 32 | image: docker.cloudimages.asia/aidemoonio/moon-frontend:latest 33 | container_name: web 34 | ports: 35 | - "5173:80" -------------------------------------------------------------------------------- /deploy/docker/moon/houyi/config.yaml: -------------------------------------------------------------------------------- 1 | env: dev 2 | 3 | dependPalace: true 4 | server: 5 | name: moon_houyi 6 | httpEndpoint: "houyi.application.svc.cluster.local:8001" 7 | grpcEndpoint: "houyi.application.svc.cluster.local:9001" 8 | network: "rpc" 9 | metadata: 10 | description: 是moon监控系列的告警组件,可以独立部署,接受prom类型规则,也可以接受alertmanager类型组件的告警推送 11 | background: 寓意为天神后羿,专门用于监控规则告警事件 12 | http: 13 | addr: 0.0.0.0:8001 14 | timeout: 50s 15 | grpc: 16 | addr: 0.0.0.0:9001 17 | timeout: 50s 18 | 19 | cache: 20 | driver: "redis" 21 | redis: 22 | network: "tcp" 23 | addr: redis.middleware.svc.cluster.local:6379 24 | db: 0 25 | password: "lQz8OMgje7UyoD" 26 | read_timeout: 0.2s 27 | write_timeout: 0.2s 28 | dial_timeout: 0.2s 29 | 30 | watch: 31 | strategy: 32 | timeout: 10s 33 | interval: "@every 10s" 34 | alertEvent: 35 | timeout: 10s 36 | interval: 10s 37 | 38 | palace_server: 39 | network: "rpc" 40 | nodeVersion: "" 41 | endpoint: "palace.application.svc.cluster.local:9000" 42 | timeout: 50s 43 | secret: "" 44 | -------------------------------------------------------------------------------- /deploy/k8s/moon/README.md: -------------------------------------------------------------------------------- 1 | # 使用前请配置配置文件中的各个连接信息、oauth2配置、email配置等 -------------------------------------------------------------------------------- /deploy/k8s/moon/houyi/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: houyi 5 | namespace: application 6 | labels: 7 | app: houyi 8 | spec: 9 | replicas: 1 10 | selector: 11 | matchLabels: 12 | app: houyi 13 | template: 14 | metadata: 15 | labels: 16 | app: houyi 17 | spec: 18 | containers: 19 | - name: houyi 20 | image: docker.cloudimages.asia/aidemoonio/houyi:latest 21 | imagePullPolicy: IfNotPresent 22 | ports: 23 | - name: http 24 | containerPort: 8001 25 | - name: grpc 26 | containerPort: 9001 27 | volumeMounts: 28 | - name: houyi-config 29 | mountPath: /data/conf/config.yaml 30 | subPath: config.yaml 31 | volumes: 32 | - name: houyi-config 33 | configMap: 34 | name: houyi-config 35 | -------------------------------------------------------------------------------- /deploy/k8s/moon/houyi/service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: houyi 5 | namespace: application 6 | labels: 7 | app: houyi 8 | spec: 9 | type: ClusterIP 10 | selector: 11 | app: houyi 12 | ports: 13 | - name: http 14 | port: 8001 15 | targetPort: http 16 | - name: grpc 17 | port: 9001 18 | targetPort: grpc 19 | 20 | -------------------------------------------------------------------------------- /deploy/k8s/moon/moon-frontend/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: moon-frontend 5 | namespace: application 6 | labels: 7 | app: moon-frontend 8 | spec: 9 | replicas: 1 10 | selector: 11 | matchLabels: 12 | app: moon-frontend 13 | template: 14 | metadata: 15 | labels: 16 | app: moon-frontend 17 | spec: 18 | containers: 19 | - name: moon-frontend 20 | image: docker.cloudimages.asia/aidemoonio/moon-frontend:latest 21 | imagePullPolicy: IfNotPresent 22 | ports: 23 | - name: http 24 | containerPort: 80 25 | -------------------------------------------------------------------------------- /deploy/k8s/moon/moon-frontend/ingress.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: networking.k8s.io/v1 2 | kind: Ingress 3 | metadata: 4 | name: moon-frontend 5 | namespace: application 6 | labels: 7 | app: moon-frontend 8 | spec: 9 | ingressClassName: nginx 10 | tls: 11 | - secretName: moon 12 | hosts: 13 | - moon.aide-cloud.cn 14 | rules: 15 | - host: moon.aide-cloud.cn 16 | http: 17 | paths: 18 | - path: / 19 | pathType: Prefix 20 | backend: 21 | service: 22 | name: moon-frontend 23 | port: 24 | number: 80 25 | 26 | -------------------------------------------------------------------------------- /deploy/k8s/moon/moon-frontend/service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: moon-frontend 5 | namespace: application 6 | labels: 7 | app: moon-frontend 8 | spec: 9 | type: ClusterIP 10 | selector: 11 | app: moon-frontend 12 | ports: 13 | - name: http 14 | port: 80 15 | targetPort: http 16 | -------------------------------------------------------------------------------- /deploy/k8s/moon/palace/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: palace 5 | namespace: application 6 | labels: 7 | app: palace 8 | spec: 9 | replicas: 1 10 | selector: 11 | matchLabels: 12 | app: palace 13 | template: 14 | metadata: 15 | labels: 16 | app: palace 17 | spec: 18 | containers: 19 | - name: palace 20 | image: docker.cloudimages.asia/aidemoonio/palace:latest 21 | imagePullPolicy: IfNotPresent 22 | ports: 23 | - name: http 24 | containerPort: 8000 25 | - name: grpc 26 | containerPort: 9000 27 | readinessProbe: 28 | httpGet: 29 | path: /health 30 | port: 8000 31 | initialDelaySeconds: 5 32 | periodSeconds: 10 33 | livenessProbe: 34 | httpGet: 35 | path: /health 36 | port: 8000 37 | initialDelaySeconds: 15 38 | periodSeconds: 20 39 | volumeMounts: 40 | - name: palace-data 41 | mountPath: /data/conf/config.yaml 42 | subPath: config.yaml 43 | volumes: 44 | - name: palace-data 45 | configMap: 46 | name: palace-config 47 | -------------------------------------------------------------------------------- /deploy/k8s/moon/palace/ingress.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: networking.k8s.io/v1 2 | kind: Ingress 3 | metadata: 4 | name: palace 5 | namespace: application 6 | labels: 7 | app: palace 8 | annotations: 9 | nginx.ingress.kubernetes.io/rewrite-target: /$2 10 | spec: 11 | ingressClassName: nginx 12 | tls: 13 | - secretName: moon 14 | hosts: 15 | - moon.aide-cloud.cn 16 | rules: 17 | - host: moon.aide-cloud.cn 18 | http: 19 | paths: 20 | - path: /api(/|$)(.*) 21 | pathType: ImplementationSpecific 22 | backend: 23 | service: 24 | name: palace 25 | port: 26 | number: 8000 27 | -------------------------------------------------------------------------------- /deploy/k8s/moon/palace/service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: palace 5 | namespace: application 6 | labels: 7 | app: palace 8 | spec: 9 | type: ClusterIP 10 | selector: 11 | app: palace 12 | ports: 13 | - name: http 14 | port: 8000 15 | targetPort: http 16 | - name: grpc 17 | port: 9000 18 | targetPort: grpc 19 | 20 | -------------------------------------------------------------------------------- /deploy/k8s/moon/rabbit/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: rabbit 5 | namespace: application 6 | labels: 7 | app: rabbit 8 | spec: 9 | replicas: 1 10 | selector: 11 | matchLabels: 12 | app: rabbit 13 | template: 14 | metadata: 15 | labels: 16 | app: rabbit 17 | spec: 18 | containers: 19 | - name: rabbit 20 | image: docker.cloudimages.asia/aidemoonio/rabbit:latest 21 | imagePullPolicy: IfNotPresent 22 | ports: 23 | - name: http 24 | containerPort: 8002 25 | - name: grpc 26 | containerPort: 9002 27 | volumeMounts: 28 | - name: rabbit-data 29 | mountPath: /data/conf/config.yaml 30 | subPath: config.yaml 31 | volumes: 32 | - name: rabbit-data 33 | configMap: 34 | name: rabbit-config 35 | -------------------------------------------------------------------------------- /deploy/k8s/moon/rabbit/service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: rabbit 5 | namespace: application 6 | labels: 7 | app: rabbit 8 | spec: 9 | type: ClusterIP 10 | selector: 11 | app: rabbit 12 | ports: 13 | - name: http 14 | port: 8002 15 | targetPort: http 16 | - name: grpc 17 | port: 9002 18 | targetPort: grpc 19 | 20 | -------------------------------------------------------------------------------- /docs/i18n/quick-start.md: -------------------------------------------------------------------------------- 1 | # quick start 2 | 3 | ## [k8s deploy config](../../../deploy/k8s/moon) 4 | 5 | * [palace](../../deploy/k8s/moon/palace/configmap.yaml) 6 | * [houyi](../../deploy/k8s/moon/houyi/configmap.yaml) 7 | * [rabbit](../../deploy/k8s/moon/rabbit/configmap.yaml) 8 | * [frontend](../../deploy/k8s/moon/moon-frontend/ingress.yaml) 9 | 10 | > If you are having trouble with the deployment, please contact us in the community and we will respond as soon as possible. Or submit an issue, we will reply in a timely manner. -------------------------------------------------------------------------------- /docs/i18n/zh-CN/quick-start.md: -------------------------------------------------------------------------------- 1 | # 快速开始 2 | 3 | [快速开始文档](https://aide-family.github.io/docs/category/%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B) 4 | 5 | ## [k8s部署配置](../../../deploy/k8s/moon) 6 | 7 | * [palace](../../../deploy/k8s/moon/palace/configmap.yaml) 8 | * [houyi](../../../deploy/k8s/moon/houyi/configmap.yaml) 9 | * [rabbit](../../../deploy/k8s/moon/rabbit/configmap.yaml) 10 | * [frontend](../../../deploy/k8s/moon/moon-frontend/ingress.yaml) 11 | 12 | > 如果你部署遇到了困难, 不妨在社区联系我们, 我们会及时回复。或者提issue, 我们也会及时回复。 13 | 14 | ## [docker部署配置](../../../deploy/docker/moon) -------------------------------------------------------------------------------- /docs/images/architecture-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aide-family/moon/026ab5a5f1686673f02e89de87ef5fc7a909fcd5/docs/images/architecture-en.png -------------------------------------------------------------------------------- /docs/images/architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aide-family/moon/026ab5a5f1686673f02e89de87ef5fc7a909fcd5/docs/images/architecture.png -------------------------------------------------------------------------------- /docs/images/feishu-moon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aide-family/moon/026ab5a5f1686673f02e89de87ef5fc7a909fcd5/docs/images/feishu-moon.png -------------------------------------------------------------------------------- /docs/images/goland-config.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aide-family/moon/026ab5a5f1686673f02e89de87ef5fc7a909fcd5/docs/images/goland-config.png -------------------------------------------------------------------------------- /docs/images/make-api.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aide-family/moon/026ab5a5f1686673f02e89de87ef5fc7a909fcd5/docs/images/make-api.png -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | echo The value of CMD_PARAMS_ENV is: $CMD_PARAMS_ENV 3 | /app/$CMD_PARAMS_ENV -c /data/conf -config_ext $CONFIG_TYPE -------------------------------------------------------------------------------- /pkg/helper/metric/counter_alarm.go: -------------------------------------------------------------------------------- 1 | package metric 2 | 3 | import "github.com/prometheus/client_golang/prometheus" 4 | 5 | var alarmCounter = prometheus.NewCounterVec( 6 | prometheus.CounterOpts{ 7 | Namespace: "", 8 | Subsystem: "", 9 | Name: "alarm_total", 10 | Help: "count of alarm", 11 | }, 12 | []string{"level_id", "strategy_id", "team_id", "strategy_name"}, 13 | ) 14 | 15 | func init() { 16 | prometheus.MustRegister(alarmCounter) 17 | } 18 | 19 | // IncAlarmCounter 告警计数器+1 20 | func IncAlarmCounter(levelID, strategyID, teamID, strategyName string) { 21 | alarmCounter.WithLabelValues(levelID, strategyID, teamID, strategyName).Inc() 22 | } 23 | 24 | // AddAlarmCounter 告警计数器+n 25 | func AddAlarmCounter(levelID, strategyID, teamID, strategyName string, n float64) { 26 | alarmCounter.WithLabelValues(levelID, strategyID, teamID, strategyName).Add(n) 27 | } 28 | -------------------------------------------------------------------------------- /pkg/helper/metric/counter_notify.go: -------------------------------------------------------------------------------- 1 | package metric 2 | 3 | import "github.com/prometheus/client_golang/prometheus" 4 | 5 | var notifyCounter = prometheus.NewCounterVec( 6 | prometheus.CounterOpts{ 7 | Namespace: "", 8 | Subsystem: "", 9 | Name: "notify_total", 10 | Help: "count of notify", 11 | }, 12 | []string{"team_id", "status", "notify_id", "notify_name"}, 13 | ) 14 | 15 | func init() { 16 | prometheus.MustRegister(notifyCounter) 17 | } 18 | 19 | // IncNotifyCounter 通知计数器+1 20 | func IncNotifyCounter(teamID, notifyStatus, notifyID, notifyName string) { 21 | notifyCounter.WithLabelValues(teamID, notifyStatus, notifyID, notifyName).Inc() 22 | } 23 | -------------------------------------------------------------------------------- /pkg/helper/metric/counter_request.go: -------------------------------------------------------------------------------- 1 | package metric 2 | 3 | import ( 4 | "github.com/prometheus/client_golang/prometheus" 5 | ) 6 | 7 | var requestCounter = prometheus.NewCounterVec( 8 | prometheus.CounterOpts{ 9 | Namespace: "", 10 | Subsystem: "", 11 | Name: "request_total", 12 | Help: "count of requests received", 13 | }, 14 | []string{"component", "path"}, 15 | ) 16 | 17 | func init() { 18 | prometheus.MustRegister(requestCounter) 19 | } 20 | 21 | // IncRequestCounter increments the QPS counter for the given method and path. 22 | func IncRequestCounter(component, path string) { 23 | requestCounter.WithLabelValues(component, path).Inc() 24 | } 25 | -------------------------------------------------------------------------------- /pkg/helper/metric/counter_request_err.go: -------------------------------------------------------------------------------- 1 | package metric 2 | 3 | import ( 4 | "github.com/prometheus/client_golang/prometheus" 5 | ) 6 | 7 | var counterRequestErr = prometheus.NewCounterVec( 8 | prometheus.CounterOpts{ 9 | Name: "counter_request_err", 10 | Help: "Counter of request error", 11 | }, 12 | []string{"component", "path", "code"}, 13 | ) 14 | 15 | func init() { 16 | prometheus.MustRegister(counterRequestErr) 17 | } 18 | 19 | // IncCounterRequestErr increments the counter of request error. 20 | func IncCounterRequestErr(component, path string, code int32) { 21 | var status string 22 | // 5xx error 23 | if code >= 500 && code < 600 { 24 | status = "5xx" 25 | } 26 | // 4xx error 27 | if code >= 400 && code < 500 { 28 | status = "4xx" 29 | } 30 | // 3xx error 31 | if code >= 300 && code < 400 { 32 | status = "3xx" 33 | } 34 | // 2xx error 35 | if code >= 200 && code < 300 { 36 | status = "2xx" 37 | } 38 | 39 | counterRequestErr.WithLabelValues(component, path, status).Inc() 40 | } 41 | -------------------------------------------------------------------------------- /pkg/helper/metric/gauge_alarm.go: -------------------------------------------------------------------------------- 1 | package metric 2 | 3 | import "github.com/prometheus/client_golang/prometheus" 4 | 5 | var alarmGauge = prometheus.NewGaugeVec( 6 | prometheus.GaugeOpts{ 7 | Namespace: "", 8 | Subsystem: "", 9 | Name: "alarm_realtime_total", 10 | Help: "count of alarm", 11 | }, 12 | []string{"level_id", "strategy_id", "team_id", "strategy_name"}, 13 | ) 14 | 15 | func init() { 16 | prometheus.MustRegister(alarmGauge) 17 | } 18 | 19 | // IncAlarmGauge 告警计数器+1 20 | func IncAlarmGauge(levelID, strategyID, teamID, strategyName string) { 21 | alarmGauge.WithLabelValues(levelID, strategyID, teamID, strategyName).Inc() 22 | } 23 | 24 | // DecAlarmGauge 告警计数器-1 25 | func DecAlarmGauge(levelID, strategyID, teamID, strategyName string) { 26 | alarmGauge.WithLabelValues(levelID, strategyID, teamID, strategyName).Dec() 27 | } 28 | -------------------------------------------------------------------------------- /pkg/helper/metric/histogram_response_time.go: -------------------------------------------------------------------------------- 1 | package metric 2 | 3 | import ( 4 | "github.com/prometheus/client_golang/prometheus" 5 | ) 6 | 7 | var responseTimeHistogram = prometheus.NewHistogramVec(prometheus.HistogramOpts{ 8 | Name: "api_response_time_seconds", 9 | Help: "Histogram for the response time of the API", 10 | Buckets: prometheus.ExponentialBuckets(0.001, 2, 15), // 定义时间桶,例如从1ms开始,倍数为2,共15个桶 11 | }, []string{"component", "path"}) 12 | 13 | func init() { 14 | prometheus.MustRegister(responseTimeHistogram) 15 | } 16 | 17 | // RecordResponseTime 记录响应时间 18 | func RecordResponseTime(component, path string, duration float64) { 19 | responseTimeHistogram.WithLabelValues(component, path).Observe(duration) 20 | } 21 | -------------------------------------------------------------------------------- /pkg/helper/metric/metric.go: -------------------------------------------------------------------------------- 1 | package metric 2 | 3 | import ( 4 | "net/http" 5 | "strings" 6 | 7 | "github.com/prometheus/client_golang/prometheus/promhttp" 8 | ) 9 | 10 | var _ http.Handler = &metric{} 11 | 12 | type metric struct { 13 | token string 14 | } 15 | 16 | // NewMetricHandler 创建指标处理对象 17 | func NewMetricHandler(token string) http.Handler { 18 | return &metric{token: strings.TrimSpace(token)} 19 | } 20 | 21 | // ServeHTTP 处理HTTP请求 22 | func (m *metric) ServeHTTP(writer http.ResponseWriter, request *http.Request) { 23 | // 从URL中获取token 24 | if m.validateToken(request) { 25 | writer.WriteHeader(http.StatusUnauthorized) 26 | return 27 | } 28 | promhttp.Handler().ServeHTTP(writer, request) 29 | } 30 | 31 | func (m *metric) validateToken(request *http.Request) bool { 32 | if m.token == "" { 33 | return false 34 | } 35 | token := request.URL.Query().Get("token") 36 | return token == m.token 37 | } 38 | -------------------------------------------------------------------------------- /pkg/helper/middleware/cors.go: -------------------------------------------------------------------------------- 1 | package middleware 2 | 3 | import ( 4 | "net/http" 5 | 6 | "github.com/gorilla/handlers" 7 | ) 8 | 9 | // Cors 跨域中间件 10 | func Cors() func(http.Handler) http.Handler { 11 | return handlers.CORS( 12 | handlers.AllowedOriginValidator(func(origin string) bool { 13 | return true 14 | }), 15 | handlers.AllowedHeaders([]string{ 16 | "Origin", 17 | "Content-Length", 18 | "Content-Type", 19 | "Authorization", 20 | "content-type-original", 21 | "x-requested-with", 22 | "accept", 23 | "origin", 24 | "user-agent", 25 | "*", 26 | "User-Agent", 27 | "Referer", 28 | "Accept-Encoding", 29 | "Accept-Language", 30 | "X-Requested-With", 31 | XSourceTypeHeader, 32 | XTeamIDHeader, 33 | XTeamMemberIDHeader, 34 | }), 35 | handlers.AllowedMethods([]string{"GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"}), 36 | handlers.AllowCredentials(), 37 | ) 38 | } 39 | -------------------------------------------------------------------------------- /pkg/helper/middleware/rbac.go: -------------------------------------------------------------------------------- 1 | package middleware 2 | 3 | import ( 4 | "context" 5 | 6 | authorizationapi "github.com/aide-family/moon/api/admin/authorization" 7 | "github.com/aide-family/moon/pkg/merr" 8 | 9 | "github.com/go-kratos/kratos/v2/middleware" 10 | "github.com/go-kratos/kratos/v2/transport" 11 | ) 12 | 13 | // CheckRbacFun 权限校验函数 14 | type CheckRbacFun func(ctx context.Context, operation string) (*authorizationapi.CheckPermissionReply, error) 15 | 16 | // Rbac 权限校验中间件 17 | func Rbac(check CheckRbacFun) middleware.Middleware { 18 | return func(handler middleware.Handler) middleware.Handler { 19 | return func(ctx context.Context, req interface{}) (reply interface{}, err error) { 20 | operation, ok := transport.FromServerContext(ctx) 21 | if !ok { 22 | return nil, merr.ErrorNotification("get operation failed") 23 | } 24 | // 判断该用户在该资源是否有权限 25 | if _, err = check(ctx, operation.Operation()); err != nil { 26 | return nil, err 27 | } 28 | return handler(ctx, req) 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /pkg/helper/middleware/sourcetype.go: -------------------------------------------------------------------------------- 1 | package middleware 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/pkg/vobj" 7 | 8 | "github.com/go-kratos/kratos/v2/middleware" 9 | "github.com/go-kratos/kratos/v2/transport" 10 | ) 11 | 12 | const XSourceTypeHeader = "X-Source-Type" 13 | 14 | // SourceType 获取请求头中的Source-Type sourceType System Team 15 | func SourceType() middleware.Middleware { 16 | return func(handler middleware.Handler) middleware.Handler { 17 | return func(ctx context.Context, req interface{}) (reply interface{}, err error) { 18 | if tr, ok := transport.FromServerContext(ctx); ok { 19 | sourceCode := tr.RequestHeader().Get(XSourceTypeHeader) 20 | ctx = context.WithValue(ctx, sourceTypeKey{}, vobj.GetSourceType(sourceCode)) 21 | } 22 | 23 | return handler(ctx, req) 24 | } 25 | } 26 | } 27 | 28 | // SourceTypeInfo Request header source 29 | type sourceTypeKey struct{} 30 | 31 | // GetSourceType get source type 32 | func GetSourceType(ctx context.Context) vobj.SourceType { 33 | sourceTypeInfo, ok := ctx.Value(sourceTypeKey{}).(vobj.SourceType) 34 | if ok { 35 | return sourceTypeInfo 36 | } 37 | return vobj.SourceTypeTeam 38 | } 39 | -------------------------------------------------------------------------------- /pkg/helper/middleware/timeout.go: -------------------------------------------------------------------------------- 1 | package middleware 2 | 3 | import ( 4 | "context" 5 | "time" 6 | 7 | "github.com/go-kratos/kratos/v2/middleware" 8 | ) 9 | 10 | // Timeout ctx timeout 11 | func Timeout(t time.Duration) middleware.Middleware { 12 | return func(handler middleware.Handler) middleware.Handler { 13 | return func(ctx context.Context, req interface{}) (interface{}, error) { 14 | if t <= 0 { 15 | return handler(ctx, req) 16 | } 17 | ctx, cancel := context.WithTimeout(ctx, t) 18 | defer cancel() 19 | return handler(ctx, req) 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /pkg/helper/pprof.go: -------------------------------------------------------------------------------- 1 | package helper 2 | 3 | import ( 4 | "net/http" 5 | // 注册pprof 6 | _ "net/http/pprof" 7 | 8 | "github.com/go-kratos/kratos/v2/log" 9 | ) 10 | 11 | // Pprof 开启pprof 12 | func Pprof(address string) { 13 | if address == "" { 14 | return 15 | } 16 | go func() { 17 | if err := http.ListenAndServe(address, nil); err != nil { 18 | log.Errorf("pprof listen and serve error: %v", err) 19 | } 20 | }() 21 | } 22 | -------------------------------------------------------------------------------- /pkg/helper/sse/sse.go: -------------------------------------------------------------------------------- 1 | package sse 2 | 3 | import ( 4 | "net/http" 5 | "strings" 6 | 7 | "github.com/aide-family/moon/pkg/helper/middleware" 8 | "github.com/go-kratos/kratos/v2/log" 9 | ) 10 | 11 | // NewSSEHandler handles the SSE connection 12 | func NewSSEHandler(clientManager *ClientManager) http.HandlerFunc { 13 | return func(w http.ResponseWriter, r *http.Request) { 14 | token := r.URL.Query().Get("token") 15 | if token == "" { 16 | http.Error(w, "token is required", http.StatusBadRequest) 17 | return 18 | } 19 | // 设置HTTP头部,指定这是一个SSE连接 20 | w.Header().Set("Content-Type", "text/event-stream") 21 | w.Header().Set("Cache-Control", "no-cache") 22 | w.Header().Set("Connection", "keep-alive") 23 | 24 | claims, ok := middleware.ParseJwtClaimsFromToken(strings.TrimPrefix(token, "Bearer ")) 25 | if !ok { 26 | http.Error(w, "token is invalid", http.StatusUnauthorized) 27 | return 28 | } 29 | 30 | client := NewClient(claims.GetUser()) 31 | clientManager.AddClient(client) 32 | defer func() { 33 | clientManager.RemoveClient(client.ID) 34 | }() 35 | 36 | go client.WriteSSE(w) 37 | <-r.Context().Done() 38 | log.Infof("client %d disconnected", client.ID) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /pkg/helper/string.go: -------------------------------------------------------------------------------- 1 | package helper 2 | 3 | import ( 4 | "regexp" 5 | 6 | "github.com/aide-family/moon/pkg/merr" 7 | "github.com/aide-family/moon/pkg/util/types" 8 | ) 9 | 10 | // CheckEmail 检查邮箱格式 11 | func CheckEmail(email string) error { 12 | match := regexp.MustCompile(`^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$`) 13 | if types.TextIsNull(email) || !match.MatchString(email) { 14 | return merr.ErrorAlert("邮箱格式不正确").WithMetadata(map[string]string{ 15 | "email": email, 16 | }) 17 | } 18 | return nil 19 | } 20 | -------------------------------------------------------------------------------- /pkg/houyi/datasource/endpoint_duration_test.go: -------------------------------------------------------------------------------- 1 | package datasource_test 2 | 3 | import ( 4 | "context" 5 | "encoding/json" 6 | "testing" 7 | "time" 8 | 9 | "github.com/aide-family/moon/pkg/houyi/datasource" 10 | "github.com/aide-family/moon/pkg/vobj" 11 | ) 12 | 13 | func TestEndpointDuration(t *testing.T) { 14 | ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) 15 | defer cancel() 16 | url := "http://www.baidu.com" 17 | res := datasource.EndpointDuration(ctx, url, vobj.HTTPMethodGet, nil, "", 5*time.Second) 18 | for _, point := range res { 19 | bs, _ := json.Marshal(point) 20 | t.Log(string(bs)) 21 | } 22 | 23 | url = "https://www.baidu.com" 24 | res = datasource.EndpointDuration(ctx, url, vobj.HTTPMethodGet, nil, "", 5*time.Second) 25 | for _, point := range res { 26 | bs, _ := json.Marshal(point) 27 | t.Log(string(bs)) 28 | } 29 | 30 | url = "https://www.baidu.com" 31 | res = datasource.EndpointDuration(ctx, url, vobj.HTTPMethodPost, nil, "", 5*time.Second) 32 | for _, point := range res { 33 | bs, _ := json.Marshal(point) 34 | t.Log(string(bs)) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /pkg/houyi/datasource/victoriametrics_test.go: -------------------------------------------------------------------------------- 1 | package datasource_test 2 | 3 | import ( 4 | "context" 5 | "testing" 6 | "time" 7 | 8 | "github.com/aide-family/moon/pkg/houyi/datasource" 9 | "github.com/aide-family/moon/pkg/util/types" 10 | "google.golang.org/protobuf/types/known/durationpb" 11 | ) 12 | 13 | func TestNewVictoriametricsDatasource(t *testing.T) { 14 | opts := []datasource.VictoriaMetricsDatasourceOption{ 15 | datasource.WithVictoriaMetricsEndpoint("https://victoriametrics.aide-cloud.cn"), 16 | } 17 | vmData := datasource.NewVictoriaMetricsDatasource(opts...) 18 | durationT := types.NewDuration(durationpb.New(60 * time.Second)) 19 | endAt := time.Now() 20 | startAt := types.NewTime(endAt.Add(-durationT.Duration.AsDuration())) 21 | queryRange, err := vmData.QueryRange(context.Background(), "up", startAt.Unix(), endAt.Unix(), 10) 22 | if err != nil { 23 | t.Fatal(err) 24 | } 25 | bs, _ := types.Marshal(queryRange) 26 | t.Log(string(bs)) 27 | 28 | eval, err := datasource.MetricEval(vmData)(context.Background(), "up", durationT) 29 | if err != nil { 30 | t.Fatal(err) 31 | } 32 | for indexer, point := range eval { 33 | t.Log("idnex", indexer) 34 | pointBs, _ := types.Marshal(point) 35 | t.Log("point", string(pointBs)) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /pkg/houyi/logs/logs.go: -------------------------------------------------------------------------------- 1 | package logs 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/aide-family/moon/pkg/conf" 7 | "github.com/aide-family/moon/pkg/houyi/datasource" 8 | "github.com/aide-family/moon/pkg/merr" 9 | ) 10 | 11 | const ( 12 | logElasticsearch = "elasticsearch" 13 | logLoki = "loki" 14 | logAliAliCloudSLS = "aliYunSls" 15 | ) 16 | 17 | // NewLogQuery creates a new log query based on the configuration. 18 | func NewLogQuery(c *conf.LogQuery) (datasource.LogDatasource, error) { 19 | switch strings.ToLower(c.GetType()) { 20 | case logElasticsearch: 21 | es := c.GetEs() 22 | return NewElasticsearch(es, WithEsEndpoint(es.GetEndpoint())) 23 | case logLoki: 24 | loki := c.GetLoki() 25 | return NewLokiDatasource(WithLokiEndpoint(loki.GetEndpoint()), 26 | WithLokiBasicAuth(loki.GetUsername(), loki.GetPassword()), 27 | WithLokiLimit(loki.GetLimit())), nil 28 | case logAliAliCloudSLS: 29 | aliYun := c.GetAliYun() 30 | return NewAliYunLog(aliYun, WithAliYunEndpoint(aliYun.GetEndpoint())), nil 31 | default: 32 | return nil, merr.ErrorNotificationSystemError("不支持的日志查询类型:%s", c.GetType()) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /pkg/houyi/mq/mq_test.go: -------------------------------------------------------------------------------- 1 | package mq 2 | 3 | import ( 4 | "strconv" 5 | "testing" 6 | "time" 7 | ) 8 | 9 | func TestNewMockMQ(t *testing.T) { 10 | mq := NewMockMQ() 11 | defer mq.Close() 12 | 13 | ch := mq.Receive("test") 14 | go func() { 15 | for msg := range ch { 16 | t.Logf("receive message: %s", msg.Data) 17 | } 18 | t.Log("receiver exit") 19 | }() 20 | for i := 0; i < 10; i++ { 21 | mq.Send("test", []byte("hello world "+strconv.Itoa(i))) 22 | time.Sleep(time.Second) 23 | if i == 5 { 24 | mq.RemoveReceiver("test") 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /pkg/label/annotation_test.go: -------------------------------------------------------------------------------- 1 | package label 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/assert" 7 | ) 8 | 9 | func TestAnnotations_String(t *testing.T) { 10 | a := NewAnnotations(map[string]string{ 11 | SummaryKey: "summary", 12 | DescriptionKey: "description", 13 | }) 14 | 15 | t.Log(a.String()) 16 | } 17 | 18 | func TestAnnotations_Get(t *testing.T) { 19 | a := NewAnnotations(map[string]string{ 20 | SummaryKey: "summary", 21 | DescriptionKey: "description", 22 | }) 23 | 24 | assert.Equal(t, "summary", a.Get(SummaryKey)) 25 | assert.Equal(t, "description", a.Get(DescriptionKey)) 26 | } 27 | 28 | func TestAnnotations_Value(t *testing.T) { 29 | a := NewAnnotations(map[string]string{ 30 | SummaryKey: "summary", 31 | DescriptionKey: "description", 32 | }) 33 | v, err := a.Value() 34 | assert.Nil(t, err) 35 | t.Log(v) 36 | } 37 | 38 | func TestAnnotations_Set(t *testing.T) { 39 | a := NewAnnotations(map[string]string{}) 40 | 41 | a.Set(SummaryKey, "summary") 42 | a.Set(DescriptionKey, "description") 43 | assert.Equal(t, "summary", a.Get(SummaryKey)) 44 | assert.Equal(t, "description", a.Get(DescriptionKey)) 45 | t.Log(a) 46 | } 47 | -------------------------------------------------------------------------------- /pkg/label/label_test.go: -------------------------------------------------------------------------------- 1 | package label 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestLabels_String(t *testing.T) { 8 | label := NewLabels(map[string]string{ 9 | "__moon__domain__": "test", 10 | "__moon__domain_port__": "8080", 11 | "a": "a", 12 | }) 13 | t.Log(label.String()) 14 | } 15 | 16 | func TestLabels_Index(t *testing.T) { 17 | label := NewLabels(map[string]string{ 18 | "__moon__domain__": "test", 19 | "__moon__domain_port__": "8080", 20 | "a": "a", 21 | }) 22 | t.Log(label.Index()) 23 | } 24 | 25 | func TestLabels_Value(t *testing.T) { 26 | label := NewLabels(map[string]string{ 27 | "__moon__domain__": "test", 28 | "__moon__domain_port__": "8080", 29 | "a": "a", 30 | }) 31 | v, _ := label.Value() 32 | t.Log(string(v.([]byte))) 33 | } 34 | -------------------------------------------------------------------------------- /pkg/notify/hook/notifyapp.go: -------------------------------------------------------------------------------- 1 | package hook 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/aide-family/moon/pkg/notify" 7 | "github.com/aide-family/moon/pkg/vobj" 8 | "github.com/go-kratos/kratos/v2/errors" 9 | ) 10 | 11 | type ( 12 | // Notify 通知通用接口 13 | Notify interface { 14 | notify.Notify 15 | } 16 | 17 | // Config 通知配置 18 | Config interface { 19 | GetWebhook() string 20 | GetSecret() string 21 | GetContent() string 22 | GetTemplate() string 23 | GetType() string 24 | } 25 | ) 26 | 27 | // NewNotify 创建通知 28 | func NewNotify(config Config) (Notify, error) { 29 | switch strings.ToLower(config.GetType()) { 30 | case vobj.HookAPPDingTalk.EnUSString(): 31 | return NewDingTalk(config), nil 32 | case vobj.HookAPPWeChat.EnUSString(): 33 | return NewWechat(config), nil 34 | case vobj.HookAPPFeiShu.EnUSString(): 35 | return NewFeiShu(config), nil 36 | case vobj.HookAPPWebHook.EnUSString(): 37 | return NewOther(config), nil 38 | default: 39 | return nil, errors.New(404, "notify.hook.NewNotify", "notify app not support") 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /pkg/notify/notify.go: -------------------------------------------------------------------------------- 1 | package notify 2 | 3 | import ( 4 | "context" 5 | ) 6 | 7 | type ( 8 | // Msg is a map of string to any. 9 | Msg = map[string]any 10 | 11 | // Notify is a notification service. 12 | Notify interface { 13 | // Send sends a notification. 14 | Send(ctx context.Context, msg Msg) error 15 | // Type returns the type of the notification service. 16 | Type() string 17 | // Hash returns the hash of the notification service. 18 | Hash() string 19 | } 20 | ) 21 | -------------------------------------------------------------------------------- /pkg/notify/phone/phone.go: -------------------------------------------------------------------------------- 1 | package phone 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aide-family/moon/pkg/notify" 7 | "github.com/go-kratos/kratos/v2/log" 8 | ) 9 | 10 | // New 创建电话通知 11 | func New() Phone { 12 | return &p{} 13 | } 14 | 15 | type ( 16 | // Phone 电话通知 17 | Phone interface { 18 | notify.Notify 19 | Call(ctx context.Context) error 20 | } 21 | 22 | p struct{} 23 | ) 24 | 25 | // Hash 返回通知的唯一标识 26 | func (l *p) Hash() string { 27 | return l.Type() 28 | } 29 | 30 | // Type 返回通知类型 31 | func (l *p) Type() string { 32 | return "phone" 33 | } 34 | 35 | // Send 发送通知 36 | func (l *p) Send(ctx context.Context, msg notify.Msg) error { 37 | log.Debugw("send phone", "phone", l, "msg", msg) 38 | return nil 39 | } 40 | 41 | // Call 拨打电话 42 | func (l *p) Call(ctx context.Context) error { 43 | log.Debugw("call phone", "phone", l) 44 | return nil 45 | } 46 | -------------------------------------------------------------------------------- /pkg/palace/imodel/dict.go: -------------------------------------------------------------------------------- 1 | package imodel 2 | 3 | import ( 4 | "github.com/aide-family/moon/pkg/vobj" 5 | ) 6 | 7 | // IDict 系统字典通用接口 8 | type IDict interface { 9 | IAllFieldModel 10 | // GetName 字典名称 11 | GetName() string 12 | // GetValue 字典键值 13 | GetValue() string 14 | // GetDictType 字典类型 15 | GetDictType() vobj.DictType 16 | // GetColorType 字典颜色 17 | GetColorType() string 18 | // GetCSSClass 字典样式 19 | GetCSSClass() string 20 | // GetIcon 字典图标 21 | GetIcon() string 22 | // GetImageURL 字典图片 23 | GetImageURL() string 24 | // GetStatus 字典状态 25 | GetStatus() vobj.Status 26 | // GetLanguageCode 字典语言 27 | GetLanguageCode() vobj.Language 28 | // GetRemark 字典备注 29 | GetRemark() string 30 | } 31 | -------------------------------------------------------------------------------- /pkg/palace/imodel/model.go: -------------------------------------------------------------------------------- 1 | package imodel 2 | 3 | import ( 4 | "github.com/aide-family/moon/pkg/util/types" 5 | "gorm.io/plugin/soft_delete" 6 | ) 7 | 8 | // IBaseModel 基础模型 9 | type IBaseModel interface { 10 | // GetCreatedAt 获取创建时间 11 | GetCreatedAt() *types.Time 12 | // GetUpdatedAt 获取更新时间 13 | GetUpdatedAt() *types.Time 14 | // GetDeletedAt 获取删除时间 15 | GetDeletedAt() soft_delete.DeletedAt 16 | // GetCreatorID 获取创建者ID 17 | GetCreatorID() uint32 18 | } 19 | 20 | // IEasyModel 简单模型 21 | type IEasyModel interface { 22 | // GetID 获取ID 23 | GetID() uint32 24 | // GetCreatedAt 获取创建时间 25 | GetCreatedAt() *types.Time 26 | // GetUpdatedAt 获取更新时间 27 | GetUpdatedAt() *types.Time 28 | // GetDeletedAt 获取删除时间 29 | GetDeletedAt() soft_delete.DeletedAt 30 | } 31 | 32 | // IAllFieldModel 所有字段模型 33 | type IAllFieldModel interface { 34 | IEasyModel 35 | IBaseModel 36 | } 37 | -------------------------------------------------------------------------------- /pkg/palace/imodel/resource.go: -------------------------------------------------------------------------------- 1 | package imodel 2 | 3 | import ( 4 | "github.com/aide-family/moon/pkg/vobj" 5 | ) 6 | 7 | // IResource 资源模型 8 | type IResource interface { 9 | IAllFieldModel 10 | // GetName 获取名称 11 | GetName() string 12 | // GetPath 获取路径 13 | GetPath() string 14 | // GetStatus 获取状态 15 | GetStatus() vobj.Status 16 | // GetRemark 获取备注 17 | GetRemark() string 18 | // GetModule 获取模块 19 | GetModule() int32 20 | // GetDomain 获取领域 21 | GetDomain() int32 22 | // GetAllow 获取放行规则 23 | GetAllow() vobj.Allow 24 | } 25 | -------------------------------------------------------------------------------- /pkg/palace/imodel/send_template.go: -------------------------------------------------------------------------------- 1 | package imodel 2 | 3 | import ( 4 | "github.com/aide-family/moon/pkg/vobj" 5 | ) 6 | 7 | // ISendTemplate 发送模板 8 | type ISendTemplate interface { 9 | IAllFieldModel 10 | // GetName 获取模板名称 11 | GetName() string 12 | // GetContent 获取模板内容 13 | GetContent() string 14 | // GetSendType 获取发送类型 15 | GetSendType() vobj.AlarmSendType 16 | // GetRemark 获取备注 17 | GetRemark() string 18 | // GetStatus 获取状态 19 | GetStatus() vobj.Status 20 | } 21 | -------------------------------------------------------------------------------- /pkg/palace/model/.gitignore: -------------------------------------------------------------------------------- 1 | query -------------------------------------------------------------------------------- /pkg/palace/model/README.md: -------------------------------------------------------------------------------- 1 | # 模型关系 2 | 3 | ```mermaid 4 | --- 5 | title: 模型关系 6 | --- 7 | 8 | classDiagram 9 | BinaryMarshaler <-- BaseModel 10 | BinaryUnmarshaler <-- BaseModel 11 | BaseModel <-- AllFieldModel 12 | BaseModel <-- EasyModel 13 | 14 | AllFieldModel <-- SysDict 15 | AllFieldModel <-- SysAPI 16 | AllFieldModel <-- SysOAuthUser 17 | AllFieldModel <-- SysUser 18 | 19 | AllFieldModel <-- SysTeamInvite 20 | AllFieldModel <-- SysTeamConfig 21 | AllFieldModel <-- SysSendTemplate 22 | AllFieldModel <-- SysUserMessage 23 | 24 | SysOAuthUser --> SysUser 25 | 26 | SysUserMessage --> SysUser 27 | 28 | SysTeamInvite --> SysTeam 29 | SysTeamInvite --> SysUser 30 | 31 | AllFieldModel <-- SysTeam 32 | 33 | SysTeamConfig --> SysTeam 34 | 35 | SysSendTemplate --> SysTeam 36 | ``` 37 | -------------------------------------------------------------------------------- /pkg/palace/model/alarmmodel/.gitignore: -------------------------------------------------------------------------------- 1 | alarmquery -------------------------------------------------------------------------------- /pkg/palace/model/alarmmodel/init.go: -------------------------------------------------------------------------------- 1 | package alarmmodel 2 | 3 | // Models 注册biz alarm model下相关模型 4 | func Models() []any { 5 | return []any{ 6 | &RealtimeAlarm{}, 7 | &AlarmHistory{}, 8 | &HistoryDetails{}, 9 | &RealtimeDetails{}, 10 | &AlarmRaw{}, 11 | &RealtimeAlarmReceiver{}, 12 | &RealtimeAlarmPage{}, 13 | &AlarmSendHistory{}, 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /pkg/palace/model/alarmmodel/realtime_arlarm_page.go: -------------------------------------------------------------------------------- 1 | package alarmmodel 2 | 3 | const tableNameRealtimeAlarmPage = "realtime_alarm_page" 4 | 5 | // RealtimeAlarmPage represents the realtime alarm pages model 6 | type RealtimeAlarmPage struct { 7 | RealtimeAlarmID uint32 `gorm:"primaryKey;column:realtime_alarm_id;type:int;not null;comment:告警ID;" json:"realtime_alarm_id"` 8 | PageID uint32 `gorm:"primaryKey;column:page_id;type:int;not null;comment:页面ID" json:"page_id"` 9 | } 10 | 11 | // TableName overrides the default table name generated by gorm 12 | func (*RealtimeAlarmPage) TableName() string { 13 | return tableNameRealtimeAlarmPage 14 | } 15 | -------------------------------------------------------------------------------- /pkg/palace/model/alarmmodel/realtime_arlarm_receiver.go: -------------------------------------------------------------------------------- 1 | package alarmmodel 2 | 3 | const tableNameRealtimeAlarmReceiver = "realtime_alarm_receiver" 4 | 5 | // RealtimeAlarmReceiver represents the realtime alarm receiver model 6 | type RealtimeAlarmReceiver struct { 7 | RealtimeAlarmID uint32 `gorm:"primaryKey;column:realtime_alarm_id;type:int;not null;comment:告警ID" json:"realtime_alarm_id"` 8 | AlarmNoticeGroupID uint32 `gorm:"primaryKey;column:alarm_notice_group_id;type:int;not null;comment:告警通知组ID" json:"alarm_notice_group_id"` 9 | } 10 | 11 | // TableName overrides the default table name generated by gorm 12 | func (*RealtimeAlarmReceiver) TableName() string { 13 | return tableNameRealtimeAlarmReceiver 14 | } 15 | -------------------------------------------------------------------------------- /pkg/palace/model/bizmodel/.gitignore: -------------------------------------------------------------------------------- 1 | bizquery -------------------------------------------------------------------------------- /pkg/palace/model/bizmodel/base_model.go: -------------------------------------------------------------------------------- 1 | package bizmodel 2 | 3 | import ( 4 | "github.com/aide-family/moon/pkg/helper/middleware" 5 | "github.com/aide-family/moon/pkg/palace/model" 6 | "github.com/aide-family/moon/pkg/util/types" 7 | "gorm.io/gorm" 8 | ) 9 | 10 | // AllFieldModel 基础模型 11 | type AllFieldModel struct { 12 | model.AllFieldModel 13 | // TeamID 团队ID 14 | TeamID uint32 `gorm:"column:team_id;type:int unsigned;not null;comment:团队ID" json:"team_id"` 15 | } 16 | 17 | // GetTeamID 获取团队ID 18 | func (u *AllFieldModel) GetTeamID() uint32 { 19 | if types.IsNil(u) { 20 | return 0 21 | } 22 | if u.TeamID == 0 { 23 | u.TeamID = middleware.GetTeamID(u.GetContext()) 24 | } 25 | return u.TeamID 26 | } 27 | 28 | // BeforeCreate 创建前的hook 29 | func (u *AllFieldModel) BeforeCreate(tx *gorm.DB) (err error) { 30 | if u.GetContext() == nil { 31 | return 32 | } 33 | if err := u.AllFieldModel.BeforeCreate(tx); err != nil { 34 | return err 35 | } 36 | u.TeamID = middleware.GetTeamID(u.GetContext()) 37 | return 38 | } 39 | -------------------------------------------------------------------------------- /pkg/palace/model/bizmodel/init.go: -------------------------------------------------------------------------------- 1 | package bizmodel 2 | 3 | // Models 注册biz model下全部模型 4 | func Models() []any { 5 | return []any{ 6 | &CasbinRule{}, 7 | &Datasource{}, 8 | &DatasourceMetric{}, 9 | &MetricLabel{}, 10 | &SysTeamAPI{}, 11 | &SysTeamMemberRole{}, 12 | &SysTeamMember{}, 13 | &SysTeamRoleAPI{}, 14 | &SysTeamRole{}, 15 | &SysTeamMenu{}, 16 | &SysDict{}, 17 | &Strategy{}, 18 | &StrategyTemplate{}, 19 | &StrategyLevelTemplate{}, 20 | &SendStrategy{}, 21 | &StrategyGroup{}, 22 | &StrategyGroupCategories{}, 23 | &Dashboard{}, 24 | &DashboardChart{}, 25 | &AlarmNoticeGroup{}, 26 | &AlarmNoticeMember{}, 27 | &DashboardSelf{}, 28 | &AlarmPageSelf{}, 29 | &AlarmHook{}, 30 | &StrategySubscriber{}, 31 | &TimeEngineRule{}, 32 | &TimeEngine{}, 33 | &StrategyLevel{}, 34 | &SysSendTemplate{}, 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /pkg/palace/model/bizmodel/strategy_group_categories.go: -------------------------------------------------------------------------------- 1 | package bizmodel 2 | 3 | import ( 4 | "github.com/aide-family/moon/pkg/util/types" 5 | ) 6 | 7 | const tableNameStrategyGroupCategories = "strategy_group_categories" 8 | 9 | // StrategyGroupCategories 策略分组类型中间表 10 | type StrategyGroupCategories struct { 11 | StrategyGroupID uint32 `gorm:"primaryKey;column:strategy_group_id;type:int unsigned;primaryKey" json:"strategy_group_id"` 12 | SysDictID uint32 `gorm:"primaryKey;column:sys_dict_id;type:int unsigned;primaryKey" json:"sys_dict_id"` 13 | } 14 | 15 | // UnmarshalBinary redis存储实现 16 | func (c *StrategyGroupCategories) UnmarshalBinary(data []byte) error { 17 | return types.Unmarshal(data, c) 18 | } 19 | 20 | // MarshalBinary redis存储实现 21 | func (c *StrategyGroupCategories) MarshalBinary() (data []byte, err error) { 22 | return types.Marshal(c) 23 | } 24 | 25 | // TableName StrategyGroupCategories 's table name 26 | func (*StrategyGroupCategories) TableName() string { 27 | return tableNameStrategyGroupCategories 28 | } 29 | -------------------------------------------------------------------------------- /pkg/palace/model/bizmodel/strategy_label_notice.go: -------------------------------------------------------------------------------- 1 | package bizmodel 2 | 3 | import ( 4 | "github.com/aide-family/moon/pkg/util/types" 5 | ) 6 | 7 | // StrategyMetricsLabelNotice 策略labels表 8 | type StrategyMetricsLabelNotice struct { 9 | // label key 10 | Name string `json:"name"` 11 | // label value 12 | Value string `json:"value"` 13 | // labels告警组 14 | AlarmGroups []*AlarmNoticeGroup `json:"alarm_groups"` 15 | } 16 | 17 | // String json 序列化实现 18 | func (c *StrategyMetricsLabelNotice) String() string { 19 | if c == nil { 20 | return "{}" 21 | } 22 | bs, err := types.Marshal(c) 23 | if err != nil { 24 | return "{}" 25 | } 26 | return string(bs) 27 | } 28 | 29 | // UnmarshalBinary redis存储实现 30 | func (c *StrategyMetricsLabelNotice) UnmarshalBinary(data []byte) error { 31 | return types.Unmarshal(data, c) 32 | } 33 | 34 | // MarshalBinary redis存储实现 35 | func (c *StrategyMetricsLabelNotice) MarshalBinary() (data []byte, err error) { 36 | return types.Marshal(c) 37 | } 38 | -------------------------------------------------------------------------------- /pkg/palace/model/bizmodel/sys_team_member_roles.go: -------------------------------------------------------------------------------- 1 | package bizmodel 2 | 3 | import ( 4 | "github.com/aide-family/moon/pkg/util/types" 5 | ) 6 | 7 | const tableNameSysTeamMemberRole = "sys_team_member_roles" 8 | 9 | // SysTeamMemberRole mapped from table 10 | type SysTeamMemberRole struct { 11 | SysTeamMemberID uint32 `gorm:"primaryKey;column:sys_team_member_id;type:int unsigned;primaryKey;uniqueIndex:idx__user_id__team_id__role_id,priority:1;comment:团队用户ID" json:"sys_team_member_id"` // 团队用户ID 12 | SysTeamRoleID uint32 `gorm:"primaryKey;column:sys_team_role_id;type:int unsigned;primaryKey;uniqueIndex:idx__user_id__team_id__role_id,priority:2;comment:团队角色ID" json:"sys_team_role_id"` // 团队角色ID 13 | } 14 | 15 | // String json string 16 | func (c *SysTeamMemberRole) String() string { 17 | bs, _ := types.Marshal(c) 18 | return string(bs) 19 | } 20 | 21 | // TableName SysTeamMemberRole's table name 22 | func (*SysTeamMemberRole) TableName() string { 23 | return tableNameSysTeamMemberRole 24 | } 25 | -------------------------------------------------------------------------------- /pkg/palace/model/bizmodel/sys_team_role_apis.go: -------------------------------------------------------------------------------- 1 | package bizmodel 2 | 3 | import ( 4 | "github.com/aide-family/moon/pkg/util/types" 5 | ) 6 | 7 | const tableNameSysTeamRoleAPI = "sys_team_role_apis" 8 | 9 | // SysTeamRoleAPI mapped from table 10 | type SysTeamRoleAPI struct { 11 | SysTeamRoleID uint32 `gorm:"primaryKey;column:sys_team_role_id;type:int unsigned;primaryKey" json:"sys_team_role_id"` 12 | SysTeamAPIID uint32 `gorm:"primaryKey;column:sys_api_id;type:int unsigned;primaryKey" json:"sys_team_api_id"` 13 | } 14 | 15 | // String json string 16 | func (c *SysTeamRoleAPI) String() string { 17 | bs, _ := types.Marshal(c) 18 | return string(bs) 19 | } 20 | 21 | // TableName SysTeamRoleAPI's table name 22 | func (*SysTeamRoleAPI) TableName() string { 23 | return tableNameSysTeamRoleAPI 24 | } 25 | -------------------------------------------------------------------------------- /pkg/palace/model/init.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | // Models 注册 model 下全部模型 4 | func Models() []any { 5 | return []any{ 6 | &SysAPI{}, 7 | &SysMenu{}, 8 | &SysTeam{}, 9 | &SysTeamConfig{}, 10 | &SysUser{}, 11 | &SysDict{}, 12 | &StrategyTemplate{}, 13 | &StrategyLevelTemplate{}, 14 | &StrategyTemplateCategories{}, 15 | &SysOAuthUser{}, 16 | &SysTeamInvite{}, 17 | &SysUserMessage{}, 18 | &SysSendTemplate{}, 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /pkg/palace/model/strategy_template_categories.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import ( 4 | "github.com/aide-family/moon/pkg/util/types" 5 | ) 6 | 7 | const tableNameStrategyTemplateCategories = "strategy_template_categories" 8 | 9 | // StrategyTemplateCategories 策略模板类型 10 | type StrategyTemplateCategories struct { 11 | BaseModel 12 | StrategyTemplateID uint32 `gorm:"primaryKey"` 13 | SysDictID uint32 `gorm:"primaryKey"` 14 | } 15 | 16 | // String json string 17 | func (c *StrategyTemplateCategories) String() string { 18 | bs, _ := types.Marshal(c) 19 | return string(bs) 20 | } 21 | 22 | // UnmarshalBinary 实现redis数据转换 23 | func (c *StrategyTemplateCategories) UnmarshalBinary(data []byte) error { 24 | return types.Unmarshal(data, c) 25 | } 26 | 27 | // MarshalBinary 实现redis数据转换 28 | func (c *StrategyTemplateCategories) MarshalBinary() (data []byte, err error) { 29 | return types.Marshal(c) 30 | } 31 | 32 | // TableName StrategyTemplateCategories's table name 33 | func (*StrategyTemplateCategories) TableName() string { 34 | return tableNameStrategyTemplateCategories 35 | } 36 | -------------------------------------------------------------------------------- /pkg/plugin/event/event.go: -------------------------------------------------------------------------------- 1 | package event 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/aide-family/moon/pkg/conf" 7 | "github.com/aide-family/moon/pkg/houyi/mq" 8 | "github.com/aide-family/moon/pkg/merr" 9 | ) 10 | 11 | const ( 12 | mockMQ = "mock" 13 | rocketMQ = "rocketmq" 14 | kafkaMQ = "kafka" 15 | mqttMQ = "mqtt" 16 | ) 17 | 18 | // NewEvent 创建消息队列 19 | func NewEvent(c *conf.Event) (mq.IMQ, error) { 20 | switch strings.ToLower(c.GetType()) { 21 | case rocketMQ: 22 | return NewRocketMQEvent(c.GetRocketMQ()) 23 | case mockMQ: 24 | return mq.NewMockMQ(), nil 25 | case mqttMQ: 26 | return NewMqttEvent(c.GetMqtt()) 27 | case kafkaMQ: 28 | return NewKafkaEvent(c.GetKafka()) 29 | default: 30 | return nil, merr.ErrorNotificationSystemError("不支持的消息队列类型") 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /pkg/plugin/mlog/stdout.go: -------------------------------------------------------------------------------- 1 | package mlog 2 | 3 | import ( 4 | "io" 5 | 6 | "github.com/go-kratos/kratos/v2/log" 7 | ) 8 | 9 | type ( 10 | stdoutLog struct { 11 | write io.Writer 12 | log.Logger 13 | } 14 | ) 15 | 16 | // NewStdoutLogger new a stdout logger. 17 | func NewStdoutLogger(write io.Writer) Logger { 18 | return &stdoutLog{ 19 | write: write, 20 | Logger: log.NewStdLogger(write), 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /pkg/plugin/oss/oss.go: -------------------------------------------------------------------------------- 1 | package oss 2 | 3 | import ( 4 | "context" 5 | "io" 6 | ) 7 | 8 | type ( 9 | // Client oss 客户端 10 | Client interface { 11 | // UploadFile 上传文件 12 | UploadFile(ctx context.Context, objectName string, reader io.Reader, objectSize int64) error 13 | // DownloadFile 下载文件 14 | DownloadFile(ctx context.Context, objectName string) (io.ReadCloser, error) 15 | // DeleteFile 删除文件 16 | DeleteFile(ctx context.Context, objectName string) error 17 | // GetFileURL 获取文件访问链接 18 | GetFileURL(ctx context.Context, objectName string) (string, error) 19 | } 20 | ) 21 | -------------------------------------------------------------------------------- /pkg/util/after/recover.go: -------------------------------------------------------------------------------- 1 | package after 2 | 3 | import ( 4 | "github.com/go-kratos/kratos/v2/log" 5 | ) 6 | 7 | type ( 8 | // RecoverCallback 恢复回调 9 | RecoverCallback func(err error) 10 | ) 11 | 12 | // Recover 恢复 13 | func Recover(logHelper *log.Helper, calls ...RecoverCallback) { 14 | if err := recover(); err != nil { 15 | logHelper.Errorf("panic error: %v", err) 16 | for _, call := range calls { 17 | call(err.(error)) 18 | } 19 | } 20 | } 21 | 22 | // RecoverX 恢复, 默认使用log.Errorw 23 | func RecoverX(calls ...RecoverCallback) { 24 | if err := recover(); err != nil { 25 | log.Errorw("type", "panic", "err", err) 26 | for _, call := range calls { 27 | call(err.(error)) 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /pkg/util/captcha/captcha_test.go: -------------------------------------------------------------------------------- 1 | package captcha 2 | 3 | import ( 4 | "context" 5 | "testing" 6 | ) 7 | 8 | func TestCreateCode(t *testing.T) { 9 | code, s, err := CreateCode(context.Background(), TypeDigit, "dark", 100, 200) 10 | if err != nil { 11 | t.Error(err) 12 | return 13 | } 14 | t.Log(code) 15 | t.Log(s) 16 | t.Log(GetCodeAnswer(code)) 17 | if VerifyCaptcha(code, GetCodeAnswer(code)) { 18 | t.Log("验证成功") 19 | return 20 | } 21 | t.Error("验证失败") 22 | } 23 | -------------------------------------------------------------------------------- /pkg/util/codec/codec.go: -------------------------------------------------------------------------------- 1 | package codec 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/go-kratos/kratos/v2/encoding" 7 | ) 8 | 9 | // RegisterCodec register codec 10 | func RegisterCodec(ext string) { 11 | switch strings.ToLower(ext) { 12 | case tomlName: 13 | encoding.RegisterCodec(TomlCodec{}) 14 | default: 15 | encoding.RegisterCodec(YamlCodec{}) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /pkg/util/codec/toml.go: -------------------------------------------------------------------------------- 1 | package codec 2 | 3 | import ( 4 | "github.com/BurntSushi/toml" 5 | "github.com/go-kratos/kratos/v2/encoding" 6 | ) 7 | 8 | var _ encoding.Codec = (*TomlCodec)(nil) 9 | 10 | const tomlName = "toml" 11 | 12 | // TomlCodec is a Codec implementation with toml. 13 | // 14 | // func init() { 15 | // encoding.RegisterCodec(codec.TomlCodec{}) 16 | // } 17 | type TomlCodec struct{} 18 | 19 | // Marshal returns the wire format of v. 20 | func (TomlCodec) Marshal(v interface{}) ([]byte, error) { 21 | return toml.Marshal(v) 22 | } 23 | 24 | // Unmarshal parses the wire format into v. 25 | func (TomlCodec) Unmarshal(data []byte, v interface{}) error { 26 | return toml.Unmarshal(data, v) 27 | } 28 | 29 | // Name returns the name of the Codec implementation. The returned string 30 | // will be used as part of content type in transmission. The result must be 31 | // static; the result cannot change between calls. 32 | func (TomlCodec) Name() string { 33 | return tomlName 34 | } 35 | -------------------------------------------------------------------------------- /pkg/util/codec/yaml.go: -------------------------------------------------------------------------------- 1 | package codec 2 | 3 | import ( 4 | "gopkg.in/yaml.v3" 5 | ) 6 | 7 | const yamlName = "yaml" 8 | 9 | // YamlCodec is a Codec implementation with yaml. 10 | // 11 | // func init() { 12 | // encoding.RegisterCodec(codec.YamlCodec{}) 13 | // } 14 | type YamlCodec struct{} 15 | 16 | // Marshal returns the wire format of v. 17 | func (YamlCodec) Marshal(v interface{}) ([]byte, error) { 18 | return yaml.Marshal(v) 19 | } 20 | 21 | // Unmarshal parses the wire format into v. 22 | func (YamlCodec) Unmarshal(data []byte, v interface{}) error { 23 | return yaml.Unmarshal(data, v) 24 | } 25 | 26 | // Name returns the name of the Codec implementation. The returned string 27 | // will be used as part of content type in transmission. The result must be 28 | // static; the result cannot change between calls. 29 | func (YamlCodec) Name() string { 30 | return yamlName 31 | } 32 | -------------------------------------------------------------------------------- /pkg/util/conn/miniredis.go: -------------------------------------------------------------------------------- 1 | package conn 2 | 3 | import ( 4 | "github.com/alicebob/miniredis/v2" 5 | ) 6 | 7 | // NewMiniRedis 创建一个内存中的redis服务 8 | func NewMiniRedis() (*miniredis.Miniredis, error) { 9 | return miniredis.Run() 10 | } 11 | -------------------------------------------------------------------------------- /pkg/util/conn/miniredis_test.go: -------------------------------------------------------------------------------- 1 | package conn 2 | 3 | import ( 4 | "context" 5 | "testing" 6 | "time" 7 | 8 | "github.com/alicebob/miniredis/v2" 9 | "github.com/redis/go-redis/v9" 10 | ) 11 | 12 | func TestSomething(t *testing.T) { 13 | s := miniredis.RunT(t) 14 | 15 | // Optionally set some keys your code expects: 16 | s.Set("foo", "bar") 17 | s.HSet("some", "other", "key") 18 | 19 | // Run your code and see if it behaves. 20 | // An example using the redigo library from "github.com/gomodule/redigo/redis": 21 | c := redis.NewClient(&redis.Options{ 22 | Network: "tcp", 23 | Addr: s.Addr(), 24 | }) 25 | ctx := context.Background() 26 | err := c.Do(ctx, "SET", "foo", "bar").Err() 27 | if err != nil { 28 | t.Fatal(err) 29 | } 30 | 31 | // Optionally check values in redis... 32 | if got, err := s.Get("foo"); err != nil || got != "bar" { 33 | t.Error("'foo' has the wrong value") 34 | } 35 | // ... or use a helper for that: 36 | s.CheckGet(t, "foo", "bar") 37 | 38 | // TTL and expiration: 39 | s.Set("foo", "bar") 40 | s.SetTTL("foo", 10*time.Second) 41 | s.FastForward(11 * time.Second) 42 | if s.Exists("foo") { 43 | t.Fatal("'foo' should not have existed anymore") 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /pkg/util/conn/rbac/rbac_model.conf: -------------------------------------------------------------------------------- 1 | # Request definition 自定义请求的格式 2 | [request_definition] 3 | r = sub, obj, act 4 | 5 | # Policy definition 策略定义 6 | [policy_definition] 7 | p = sub, obj, _ 8 | p2 = sub, obj, act 9 | 10 | # Policy effect 11 | [policy_effect] 12 | e = some(where (p.eft == allow)) 13 | 14 | # Matchers 15 | [matchers] 16 | #m = r.sub == p.sub && r.obj == p.obj && r.act == p.act 17 | m = ((r.sub == p.sub || p.sub == "*") && keyMatch5(r.obj, p.obj)) || 18 | ((r.sub == p2.sub || p2.sub == "*") && keyMatch5(r.obj, p2.obj) && (r.act == p2.act || p2.act == "*")) -------------------------------------------------------------------------------- /pkg/util/conn/redis.go: -------------------------------------------------------------------------------- 1 | package conn 2 | 3 | import ( 4 | "github.com/redis/go-redis/v9" 5 | "google.golang.org/protobuf/types/known/durationpb" 6 | ) 7 | 8 | // RedisConfig redis配置 9 | type RedisConfig interface { 10 | GetNetwork() string 11 | GetAddr() string 12 | GetPassword() string 13 | GetDb() uint32 14 | GetWriteTimeout() *durationpb.Duration 15 | GetReadTimeout() *durationpb.Duration 16 | GetDialTimeout() *durationpb.Duration 17 | } 18 | 19 | // NewRedisClient 获取redis客户端 20 | func NewRedisClient(cfg RedisConfig) *redis.Client { 21 | return redis.NewClient(&redis.Options{ 22 | Addr: cfg.GetAddr(), 23 | Password: cfg.GetPassword(), 24 | DB: int(cfg.GetDb()), 25 | WriteTimeout: cfg.GetWriteTimeout().AsDuration(), 26 | ReadTimeout: cfg.GetReadTimeout().AsDuration(), 27 | DialTimeout: cfg.GetDialTimeout().AsDuration(), 28 | Network: cfg.GetNetwork(), 29 | }) 30 | } 31 | -------------------------------------------------------------------------------- /pkg/util/conn/tracer.go: -------------------------------------------------------------------------------- 1 | package conn 2 | 3 | import ( 4 | "go.opentelemetry.io/otel" 5 | "go.opentelemetry.io/otel/attribute" 6 | "go.opentelemetry.io/otel/exporters/otlp/otlptrace" 7 | "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp" 8 | "go.opentelemetry.io/otel/sdk/resource" 9 | tracesdk "go.opentelemetry.io/otel/sdk/trace" 10 | semconv "go.opentelemetry.io/otel/semconv/v1.4.0" 11 | ) 12 | 13 | // InitJaegerTracer 设置全局trace 14 | func InitJaegerTracer(serviceName, url string) error { 15 | // 创建 OTLP gRPC 导出器 16 | exp := otlptrace.NewUnstarted( 17 | otlptracehttp.NewClient( 18 | otlptracehttp.WithInsecure(), 19 | otlptracehttp.WithEndpoint(url), 20 | ), 21 | ) 22 | tp := tracesdk.NewTracerProvider( 23 | // 将基于父span的采样率设置为100% 24 | tracesdk.WithSampler(tracesdk.ParentBased(tracesdk.TraceIDRatioBased(1.0))), 25 | // 始终确保在生产中批量处理 26 | tracesdk.WithBatcher(exp), 27 | // 在资源中记录有关此应用程序的信息 28 | tracesdk.WithResource(resource.NewSchemaless( 29 | semconv.ServiceNameKey.String(serviceName), 30 | attribute.String("exporter", "jaeger"), 31 | )), 32 | ) 33 | otel.SetTracerProvider(tp) 34 | return nil 35 | } 36 | -------------------------------------------------------------------------------- /pkg/util/file/file.go: -------------------------------------------------------------------------------- 1 | package file 2 | 3 | import ( 4 | "io" 5 | "mime/multipart" 6 | "os" 7 | "path/filepath" 8 | "strings" 9 | ) 10 | 11 | // GetFileExtension 获取文件后缀 12 | func GetFileExtension(filename string) string { 13 | return filepath.Ext(filename) 14 | } 15 | 16 | // GetFileType 获取文件类型 17 | func GetFileType(fileName string) string { 18 | fileExt := GetFileExtension(fileName) 19 | return strings.Replace(fileExt, ".", "", 1) 20 | } 21 | 22 | // GetFileSizeFromPath 通过文件路径获取文件大小(字节) 23 | func GetFileSizeFromPath(filePath string) (int64, error) { 24 | fileInfo, err := os.Stat(filePath) 25 | if err != nil { 26 | return 0, err 27 | } 28 | return fileInfo.Size(), nil 29 | } 30 | 31 | // GetFileSizeFromFile 通过 multipart.File 获取文件大小(字节) 32 | // 常用于 HTTP 文件上传场景 33 | func GetFileSizeFromFile(file multipart.File) (int64, error) { 34 | // 将文件指针移到文件末尾以获取文件大小 35 | fileStat, err := file.Seek(0, io.SeekEnd) 36 | if err != nil { 37 | return 0, err 38 | } 39 | _, err = file.Seek(0, io.SeekStart) // 将指针重置回文件开头 40 | return fileStat, err 41 | } 42 | -------------------------------------------------------------------------------- /pkg/util/go/go_test.go: -------------------------------------------------------------------------------- 1 | package goroutine_test 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "time" 7 | 8 | goroutine "github.com/aide-family/moon/pkg/util/go" 9 | ) 10 | 11 | func ExampleNew() { 12 | limit := 2 13 | multiple := 2 14 | g := goroutine.New(limit, multiple) 15 | ctx := context.Background() 16 | if err := g.Start(ctx); err != nil { 17 | panic(err) 18 | } 19 | 20 | for i := range 20 { 21 | item := i 22 | goroutine.Go(func() { 23 | time.Sleep(100 * time.Millisecond) 24 | fmt.Println("msg: ", item) 25 | }) 26 | } 27 | 28 | time.Sleep(time.Second * 4) 29 | 30 | if err := g.Stop(ctx); err != nil { 31 | panic(err) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /pkg/util/httpx/httpx_test.go: -------------------------------------------------------------------------------- 1 | package httpx 2 | 3 | import ( 4 | "context" 5 | "testing" 6 | ) 7 | 8 | const baidu = "https://www.baidu.com" 9 | 10 | func TestNewHttpX(t *testing.T) { 11 | h := NewHTTPX() 12 | t.Log(h.POST(context.Background(), baidu, nil)) 13 | } 14 | -------------------------------------------------------------------------------- /pkg/util/random/uuid.go: -------------------------------------------------------------------------------- 1 | package random 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/google/uuid" 7 | ) 8 | 9 | // UUID 生成UUID 10 | func UUID(isRemoveInvalidChar ...bool) string { 11 | uid := uuid.New().String() 12 | if len(isRemoveInvalidChar) > 0 && isRemoveInvalidChar[0] { 13 | return strings.ReplaceAll(uid, "-", "") 14 | } 15 | return uid 16 | } 17 | 18 | // UUIDToUpperCase 生成UUID并转换为大写 19 | func UUIDToUpperCase(isRemoveInvalidChar ...bool) string { 20 | return strings.ToUpper(UUID(isRemoveInvalidChar...)) 21 | } 22 | -------------------------------------------------------------------------------- /pkg/util/random/uuid_test.go: -------------------------------------------------------------------------------- 1 | package random 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestUUID(t *testing.T) { 8 | t.Log(UUID()) 9 | t.Log(UUID()) 10 | t.Log(UUID(true)) 11 | t.Log(UUID(true)) 12 | } 13 | 14 | func TestUUIDToUpperCase(t *testing.T) { 15 | t.Log(UUIDToUpperCase()) 16 | t.Log(UUIDToUpperCase()) 17 | t.Log(UUIDToUpperCase(true)) 18 | t.Log(UUIDToUpperCase(true)) 19 | } 20 | -------------------------------------------------------------------------------- /pkg/util/safety/map.go: -------------------------------------------------------------------------------- 1 | package safety 2 | 3 | import ( 4 | "sync" 5 | ) 6 | 7 | // NewMap 创建一个安全的map 8 | func NewMap[K comparable, T any]() *Map[K, T] { 9 | return &Map[K, T]{ 10 | m: new(sync.Map), 11 | } 12 | } 13 | 14 | // Map 安全的map 15 | type Map[K comparable, T any] struct { 16 | m *sync.Map 17 | } 18 | 19 | // Get 获取map中的值 20 | func (m *Map[K, T]) Get(key K) (T, bool) { 21 | v, ok := m.m.Load(key) 22 | if !ok { 23 | var zero T 24 | return zero, false 25 | } 26 | return v.(T), true 27 | } 28 | 29 | // Set 设置map中的值 30 | func (m *Map[K, T]) Set(key K, value T) { 31 | m.m.Store(key, value) 32 | } 33 | 34 | // Delete 删除map中的值 35 | func (m *Map[K, T]) Delete(key K) { 36 | m.m.Delete(key) 37 | } 38 | 39 | // List 获取map中的所有值 40 | func (m *Map[K, T]) List() map[K]T { 41 | values := make(map[K]T) 42 | m.m.Range(func(key, value any) bool { 43 | values[key.(K)] = value.(T) 44 | return true 45 | }) 46 | return values 47 | } 48 | 49 | // Clear 清空map 50 | func (m *Map[K, T]) Clear() { 51 | m.m.Clear() 52 | } 53 | -------------------------------------------------------------------------------- /pkg/util/types/code.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "fmt" 5 | "regexp" 6 | "strconv" 7 | "strings" 8 | ) 9 | 10 | // MatchStatusCodes checks if the given status code matches the patterns. 11 | func MatchStatusCodes(patterns string, statusCode int) bool { 12 | // Split the patterns by commas 13 | patternList := strings.Split(patterns, ",") 14 | 15 | // Iterate through each pattern 16 | for _, pattern := range patternList { 17 | // Replace 'x' with regex pattern to match any digit 18 | regexPattern := strings.ReplaceAll(pattern, "x", "\\d") 19 | 20 | // Ensure the regex matches the full string 21 | regexPattern = "^" + regexPattern + "$" 22 | 23 | // Convert the status code to a string 24 | statusCodeStr := strconv.Itoa(statusCode) 25 | 26 | // Compile and match the regex 27 | matched, err := regexp.MatchString(regexPattern, statusCodeStr) 28 | if err != nil { 29 | fmt.Printf("Error compiling regex: %v\n", err) 30 | return false 31 | } 32 | if matched { 33 | return true 34 | } 35 | } 36 | 37 | return false 38 | } 39 | -------------------------------------------------------------------------------- /pkg/util/types/context.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "context" 5 | "time" 6 | ) 7 | 8 | var _ context.Context = (*valueOnlyContext)(nil) 9 | 10 | // valueOnlyContext 包装一个只有value的context 11 | type valueOnlyContext struct{ context.Context } 12 | 13 | func (valueOnlyContext) Deadline() (deadline time.Time, ok bool) { return } 14 | func (valueOnlyContext) Done() <-chan struct{} { return nil } 15 | func (valueOnlyContext) Err() error { return nil } 16 | 17 | // CopyValueCtx 复制一个只有value的context 18 | func CopyValueCtx(ctx context.Context) context.Context { 19 | return valueOnlyContext{ctx} 20 | } 21 | -------------------------------------------------------------------------------- /pkg/util/types/map.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import "encoding/json" 4 | 5 | // ToMap 切片转map 6 | func ToMap[T any, R comparable](list []T, f func(T) R) map[R]T { 7 | m := make(map[R]T, len(list)) 8 | for _, v := range list { 9 | m[f(v)] = v 10 | } 11 | return m 12 | } 13 | 14 | // ToMapSlice 切片转map value为切片 15 | func ToMapSlice[T any, R comparable](list []T, f func(T) R) map[R][]T { 16 | m := make(map[R][]T) 17 | for _, v := range list { 18 | key := f(v) 19 | m[key] = append(m[key], v) 20 | } 21 | return m 22 | } 23 | 24 | // MapsMerge 合并多个map 25 | func MapsMerge[K comparable, V any](ms ...map[K]V) map[K]V { 26 | m := make(map[K]V) 27 | for _, v := range ms { 28 | for k, vv := range v { 29 | m[k] = vv 30 | } 31 | } 32 | return m 33 | } 34 | 35 | // JSONToMap json转map 36 | func JSONToMap(jsonStr string) (map[string]interface{}, error) { 37 | var data map[string]interface{} 38 | err := json.Unmarshal([]byte(jsonStr), &data) 39 | if err != nil { 40 | return nil, err 41 | } 42 | return data, nil 43 | } 44 | -------------------------------------------------------------------------------- /pkg/util/types/md5.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "crypto/md5" 5 | "encoding/hex" 6 | ) 7 | 8 | // MD5 returns the MD5 checksum of the data. 9 | func MD5(str string) string { 10 | h := md5.New() 11 | h.Write([]byte(str)) 12 | return hex.EncodeToString(h.Sum(nil)) 13 | } 14 | -------------------------------------------------------------------------------- /pkg/util/types/nil.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "reflect" 5 | ) 6 | 7 | // IsNil 判断是否为nil 8 | func IsNil(i interface{}) bool { 9 | return i == nil || (reflect.ValueOf(i).Kind() == reflect.Ptr && reflect.ValueOf(i).IsNil()) 10 | } 11 | 12 | // IsNotNil 判断是否不为nil 13 | func IsNotNil(i interface{}) bool { 14 | return !IsNil(i) 15 | } 16 | -------------------------------------------------------------------------------- /pkg/util/types/object.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "reflect" 5 | ) 6 | 7 | // Of 获取对象指针 8 | func Of[T any](v T) *T { 9 | if IsNil(v) { 10 | return nil 11 | } 12 | return &v 13 | } 14 | 15 | // UnwrapOr 解包指针, 如果为nil则返回指定的默认值(没有指定,则返回go默认值), 否则返回值本身 16 | func UnwrapOr[T any](p *T, fallback ...T) T { 17 | if !IsNil(p) { 18 | return *p 19 | } 20 | if len(fallback) > 0 { 21 | return fallback[0] 22 | } 23 | var t T 24 | return t 25 | } 26 | 27 | // ExtractPointerOr 解包多层指针, 如果为nil则返回指定的默认值(没有指定,则返回go默认值), 否则返回值本身 28 | func ExtractPointerOr[T any](value any, fallback ...T) T { 29 | val, ok := extractPointer(value).(T) 30 | if ok { 31 | return val 32 | } 33 | if len(fallback) > 0 { 34 | return fallback[0] 35 | } 36 | var t T 37 | return t 38 | } 39 | 40 | func extractPointer(value any) any { 41 | t := reflect.TypeOf(value) 42 | v := reflect.ValueOf(value) 43 | if IsNil(t) { 44 | return nil 45 | } 46 | if t.Kind() != reflect.Pointer { 47 | return value 48 | } 49 | return extractPointer(v.Elem().Interface()) 50 | } 51 | -------------------------------------------------------------------------------- /pkg/util/types/password_test.go: -------------------------------------------------------------------------------- 1 | package types_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/aide-family/moon/pkg/util/types" 7 | ) 8 | 9 | func TestNewPassword(t *testing.T) { 10 | pVal := "123456" 11 | enP := types.NewPassword(pVal) 12 | t.Log(enP.String()) 13 | t.Log(enP.GetSalt()) 14 | } 15 | -------------------------------------------------------------------------------- /pkg/util/types/retry.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "time" 5 | ) 6 | 7 | // Retry 函数用于实现重试机制 8 | func Retry(f func() error, maxRetries int, maxRetryDuration time.Duration) error { 9 | var err error 10 | for i := 0; i < maxRetries; i++ { 11 | if err = f(); err == nil { 12 | return nil 13 | } 14 | time.Sleep(maxRetryDuration) // 等待一段时间后重试 15 | } 16 | return err 17 | } 18 | -------------------------------------------------------------------------------- /pkg/util/types/ternary.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | // Ternary returns trueVal if condition is true, falseVal otherwise. 4 | func Ternary[T any](condition bool, trueVal, falseVal T) T { 5 | if condition { 6 | return trueVal 7 | } 8 | return falseVal 9 | } 10 | -------------------------------------------------------------------------------- /pkg/vobj/.gitignore: -------------------------------------------------------------------------------- 1 | *_string.go -------------------------------------------------------------------------------- /pkg/vobj/alarmsendtype.go: -------------------------------------------------------------------------------- 1 | package vobj 2 | 3 | // AlarmSendType 告警发送类型 4 | // 5 | //go:generate go run ../../cmd/server/stringer/cmd.go -type=AlarmSendType -linecomment 6 | type AlarmSendType int 7 | 8 | const ( 9 | // AlarmSendTypeUnknown 未知 10 | AlarmSendTypeUnknown AlarmSendType = iota // 未知 11 | // AlarmSendTypeEmail 邮件 12 | AlarmSendTypeEmail // 邮件 13 | // AlarmSendTypeSMS 短信 14 | AlarmSendTypeSMS // 短信 15 | // AlarmSendTypeDingTalk 钉钉 16 | AlarmSendTypeDingTalk // 钉钉 17 | // AlarmSendTypeFeiShu 飞书 18 | AlarmSendTypeFeiShu // 飞书 19 | // AlarmSendTypeWechat 微信 20 | AlarmSendTypeWechat // 微信 21 | // AlarmSendTypeCustom 自定义 22 | AlarmSendTypeCustom // 自定义 23 | ) 24 | 25 | // EnUSString 英文字符串 26 | func (a AlarmSendType) EnUSString() string { 27 | switch a { 28 | case AlarmSendTypeDingTalk: 29 | return "dingtalk" 30 | case AlarmSendTypeFeiShu: 31 | return "feishu" 32 | case AlarmSendTypeWechat: 33 | return "wechat" 34 | case AlarmSendTypeEmail: 35 | return "email" 36 | case AlarmSendTypeSMS: 37 | return "sms" 38 | } 39 | return "other" 40 | } 41 | -------------------------------------------------------------------------------- /pkg/vobj/alertstatus.go: -------------------------------------------------------------------------------- 1 | package vobj 2 | 3 | import ( 4 | "strings" 5 | ) 6 | 7 | // AlertStatus 告警数据状态 8 | // 9 | //go:generate go run ../../cmd/server/stringer/cmd.go -type=AlertStatus -linecomment 10 | type AlertStatus int 11 | 12 | const ( 13 | // AlertStatusUnknown 未知 14 | AlertStatusUnknown AlertStatus = iota // 未知 15 | 16 | // AlertStatusFiring firing 17 | AlertStatusFiring // firing 18 | 19 | // AlertStatusResolved resolved 20 | AlertStatusResolved // resolved 21 | 22 | // AlertStatusSilenced silenced 23 | AlertStatusSilenced // Silenced 24 | ) 25 | 26 | // ToAlertStatus convert 27 | func ToAlertStatus(s string) AlertStatus { 28 | switch strings.ToLower(s) { 29 | case "firing": 30 | return AlertStatusFiring 31 | case "resolved": 32 | return AlertStatusResolved 33 | case "silenced": 34 | return AlertStatusSilenced 35 | default: 36 | return AlertStatusUnknown 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /pkg/vobj/allow.go: -------------------------------------------------------------------------------- 1 | package vobj 2 | 3 | // Allow 允许范围 4 | // 5 | //go:generate go run ../../cmd/server/stringer/cmd.go -type=Allow -linecomment 6 | type Allow int 7 | 8 | const ( 9 | // AllowBan 禁止 10 | AllowBan Allow = iota + 1 11 | 12 | // AllowSystem 系统控制 13 | AllowSystem // 系统控制 14 | 15 | // AllowTeam 团队控制 16 | AllowTeam 17 | 18 | // AllowUser 用户控制 19 | AllowUser 20 | 21 | // AllowRBAC RBAC控制 22 | AllowRBAC // RBAC控制 23 | 24 | // AllowNone 无控制 25 | AllowNone 26 | ) 27 | -------------------------------------------------------------------------------- /pkg/vobj/biztype.go: -------------------------------------------------------------------------------- 1 | package vobj 2 | 3 | // BizType 业务类型 4 | // 5 | //go:generate go run ../../cmd/server/stringer/cmd.go -type=BizType -linecomment 6 | type BizType int 7 | 8 | const ( 9 | // BizTypeUnknown 未知 10 | BizTypeUnknown BizType = iota // unknown 11 | 12 | // BizTypeInvitation 邀请 13 | BizTypeInvitation // invitation 14 | 15 | // BizTypeInvitationRejected 邀请被拒绝 16 | BizTypeInvitationRejected // invitation_rejected 17 | 18 | // BizTypeInvitationAccepted 邀请被接受 19 | BizTypeInvitationAccepted // invitation_accepted 20 | ) 21 | -------------------------------------------------------------------------------- /pkg/vobj/bytesize.go: -------------------------------------------------------------------------------- 1 | package vobj 2 | 3 | // biteSize 4 | //go:generate go run ../../cmd/server/stringer/cmd.go -type=ByteSize -linecomment 5 | 6 | // ByteSize 字节大小 7 | type ByteSize int 8 | 9 | const ( 10 | // KB KB 11 | KB ByteSize = 1024 12 | // MB MB 13 | MB ByteSize = 1024 * KB 14 | // GB GB 15 | GB ByteSize = 1024 * MB 16 | // TB TB 17 | TB ByteSize = 1024 * GB 18 | ) 19 | -------------------------------------------------------------------------------- /pkg/vobj/condition.go: -------------------------------------------------------------------------------- 1 | package vobj 2 | 3 | // Condition 条件判断 4 | // 5 | //go:generate go run ../../cmd/server/stringer/cmd.go -type=Condition -linecomment 6 | type Condition int 7 | 8 | const ( 9 | // ConditionUnknown 未知 10 | ConditionUnknown Condition = iota // 未知 11 | 12 | // ConditionEQ 等于 13 | ConditionEQ // 等于 14 | 15 | // ConditionNE 不等于 16 | ConditionNE // 不等于 17 | 18 | // ConditionGT 大于 19 | ConditionGT // 大于 20 | 21 | // ConditionGTE 大于等于 22 | ConditionGTE // 大于等于 23 | 24 | // ConditionLT 小于 25 | ConditionLT // 小于 26 | 27 | // ConditionLTE 小于等于 28 | ConditionLTE // 小于等于 29 | ) 30 | 31 | // Judge 判断是否符合条件 32 | func (c Condition) Judge(threshold, value float64) bool { 33 | switch c { 34 | case ConditionEQ: 35 | return threshold == value 36 | case ConditionNE: 37 | return threshold != value 38 | case ConditionGT: 39 | return threshold < value 40 | case ConditionGTE: 41 | return threshold <= value 42 | case ConditionLT: 43 | return threshold > value 44 | case ConditionLTE: 45 | return threshold >= value 46 | default: 47 | return false 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /pkg/vobj/datasourcetype.go: -------------------------------------------------------------------------------- 1 | package vobj 2 | 3 | // DatasourceType 数据源类型 4 | // 5 | //go:generate go run ../../cmd/server/stringer/cmd.go -type=DatasourceType -linecomment 6 | type DatasourceType int 7 | 8 | const ( 9 | // DatasourceTypeUnknown 未知 10 | DatasourceTypeUnknown DatasourceType = iota // 未知 11 | 12 | // DatasourceTypeMetrics 监控指标 13 | DatasourceTypeMetrics // 监控指标 14 | 15 | // DatasourceTypeTrace 链路追踪 16 | DatasourceTypeTrace // 链路追踪 17 | 18 | // DatasourceTypeLog 日志 19 | DatasourceTypeLog // 日志 20 | 21 | // DatasourceTypeMQ MQ 22 | DatasourceTypeMQ // MQ 23 | ) 24 | -------------------------------------------------------------------------------- /pkg/vobj/dicttype.go: -------------------------------------------------------------------------------- 1 | package vobj 2 | 3 | // DictType 字典类型 4 | // 5 | //go:generate go run ../../cmd/server/stringer/cmd.go -type=DictType -linecomment 6 | type DictType int 7 | 8 | const ( 9 | // DictTypeUnknown 未知 10 | DictTypeUnknown DictType = iota // 未知 11 | 12 | // DictTypeStrategyCategory 策略类目 13 | DictTypeStrategyCategory // 策略类目 14 | 15 | // DictTypeStrategyGroupCategory 策略组类目 16 | DictTypeStrategyGroupCategory // 策略组类目 17 | 18 | // DictTypeAlarmLevel 告警级别 19 | DictTypeAlarmLevel // 告警级别 20 | 21 | // DictTypeAlarmPage 告警页面 22 | DictTypeAlarmPage // 告警页面 23 | ) 24 | -------------------------------------------------------------------------------- /pkg/vobj/eventdatatype.go: -------------------------------------------------------------------------------- 1 | package vobj 2 | 3 | // EventDataType Event数据类型 4 | // 5 | //go:generate go run ../../cmd/server/stringer/cmd.go -type=EventDataType -linecomment 6 | type EventDataType int 7 | 8 | const ( 9 | // EventDataTypeUnknown 未知 10 | EventDataTypeUnknown EventDataType = iota // 未知 11 | 12 | // EventDataTypeString string 13 | EventDataTypeString // string 14 | 15 | // EventDataTypeNumber number 16 | EventDataTypeNumber // number 17 | 18 | // EventDataTypeObject object 19 | EventDataTypeObject // object 20 | ) 21 | -------------------------------------------------------------------------------- /pkg/vobj/gender.go: -------------------------------------------------------------------------------- 1 | package vobj 2 | 3 | // Gender 性别 4 | // 5 | //go:generate go run ../../cmd/server/stringer/cmd.go -type=Gender -linecomment 6 | type Gender int 7 | 8 | const ( 9 | // GenderUnknown 未知 10 | GenderUnknown Gender = iota // 未知 11 | 12 | // GenderMale 男 13 | GenderMale // 男 14 | 15 | // GenderFemale 女 16 | GenderFemale // 女 17 | ) 18 | -------------------------------------------------------------------------------- /pkg/vobj/header.go: -------------------------------------------------------------------------------- 1 | package vobj 2 | 3 | type ( 4 | // Header http请求头 5 | Header struct { 6 | Name string `json:"name"` 7 | Value string `json:"value"` 8 | } 9 | ) 10 | 11 | // NewHeader 创建一个Header对象 12 | func NewHeader(name, value string) *Header { 13 | return &Header{ 14 | Name: name, 15 | Value: value, 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /pkg/vobj/hookapp.go: -------------------------------------------------------------------------------- 1 | package vobj 2 | 3 | // HookAPP hook app 类型 4 | // 5 | //go:generate go run ../../cmd/server/stringer/cmd.go -type=HookAPP -linecomment 6 | type HookAPP int 7 | 8 | const ( 9 | // HookAPPUnknown 未知 10 | HookAPPUnknown HookAPP = iota // 未知 11 | 12 | // HookAPPWebHook 自定义 13 | HookAPPWebHook // 自定义 14 | 15 | // HookAPPDingTalk 钉钉 16 | HookAPPDingTalk // 钉钉 17 | 18 | // HookAPPWeChat 企业微信 19 | HookAPPWeChat // 企业微信 20 | 21 | // HookAPPFeiShu 飞书 22 | HookAPPFeiShu // 飞书 23 | ) 24 | 25 | // EnUSString 英文字符串 26 | func (h HookAPP) EnUSString() string { 27 | switch h { 28 | case HookAPPDingTalk: 29 | return "dingtalk" 30 | case HookAPPWeChat: 31 | return "wechat" 32 | case HookAPPFeiShu: 33 | return "feishu" 34 | default: 35 | return "other" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /pkg/vobj/invitetype.go: -------------------------------------------------------------------------------- 1 | package vobj 2 | 3 | // InviteType 邀请团队状态 4 | // 5 | //go:generate go run ../../cmd/server/stringer/cmd.go -type=InviteType -linecomment 6 | type InviteType int 7 | 8 | const ( 9 | // InviteTypeUnknown 未知 10 | InviteTypeUnknown InviteType = iota // 未知 11 | 12 | // InviteTypeJoined 加入 13 | InviteTypeJoined // 加入 14 | 15 | // InviteTypeUnderReview 邀请中 16 | InviteTypeUnderReview // 邀请中 17 | 18 | // InviteTypeRejected 已拒绝 19 | InviteTypeRejected // 已拒绝 20 | ) 21 | -------------------------------------------------------------------------------- /pkg/vobj/language.go: -------------------------------------------------------------------------------- 1 | package vobj 2 | 3 | // Language 字典类型 4 | // 5 | //go:generate go run ../../cmd/server/stringer/cmd.go -type=Language -linecomment 6 | type Language int 7 | 8 | const ( 9 | // LanguageUnknown 未知 10 | LanguageUnknown Language = iota // 未知 11 | 12 | // LanguageZHCN 中文 13 | LanguageZHCN // zh-CN 14 | 15 | // LanguageENUS 英文 16 | LanguageENUS // en-US 17 | ) 18 | 19 | // ToLanguage 获取语言 20 | func ToLanguage(s string) Language { 21 | switch s { 22 | case "zh-CN": 23 | return LanguageZHCN 24 | case "en-US": 25 | return LanguageENUS 26 | default: 27 | return LanguageUnknown 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /pkg/vobj/menutype.go: -------------------------------------------------------------------------------- 1 | package vobj 2 | 3 | // MenuType 菜单类型 4 | // 5 | //go:generate go run ../../cmd/server/stringer/cmd.go -type=MenuType -linecomment 6 | type MenuType int 7 | 8 | const ( 9 | // MenuTypeUnknown 未知 10 | MenuTypeUnknown MenuType = iota // 未知 11 | 12 | // MenuTypeMenu 菜单 13 | MenuTypeMenu // 菜单 14 | 15 | // MenuTypeButton 按钮 16 | MenuTypeButton // 按钮 17 | 18 | // MenuTypeDir 文件夹 19 | MenuTypeDir // 文件夹 20 | ) 21 | -------------------------------------------------------------------------------- /pkg/vobj/metrictype.go: -------------------------------------------------------------------------------- 1 | package vobj 2 | 3 | import ( 4 | "github.com/go-kratos/kratos/v2/log" 5 | ) 6 | 7 | // MetricType 数据源类型 8 | // 9 | //go:generate go run ../../cmd/server/stringer/cmd.go -type=MetricType -linecomment 10 | type MetricType int 11 | 12 | const ( 13 | // MetricTypeUnknown 未知 14 | MetricTypeUnknown MetricType = iota // 未知 15 | 16 | // MetricTypeCounter 计数器 17 | MetricTypeCounter // 计数器 18 | 19 | // MetricTypeGauge 仪表盘 20 | MetricTypeGauge // 仪表盘 21 | 22 | // MetricTypeHistogram 直方图 23 | MetricTypeHistogram // 直方图 24 | 25 | // MetricTypeSummary 摘要 26 | MetricTypeSummary // 摘要 27 | ) 28 | 29 | // GetMetricType 获取指标类型 30 | func GetMetricType(metricType string) (m MetricType) { 31 | switch metricType { 32 | case "counter": 33 | m = MetricTypeCounter 34 | case "histogram": 35 | m = MetricTypeHistogram 36 | case "gauge": 37 | m = MetricTypeGauge 38 | case "summary": 39 | m = MetricTypeSummary 40 | default: 41 | log.Warnw("method", "GetMetricType", "metricType", metricType) 42 | m = MetricTypeUnknown 43 | } 44 | return 45 | } 46 | -------------------------------------------------------------------------------- /pkg/vobj/moduletype.go: -------------------------------------------------------------------------------- 1 | package vobj 2 | 3 | // ModuleType 模块类型 4 | // 5 | //go:generate go run ../../cmd/server/stringer/cmd.go -type=ModuleType -linecomment 6 | type ModuleType int 7 | 8 | const ( 9 | // ModuleTypeUnknown 未知 10 | ModuleTypeUnknown ModuleType = iota // 未知 11 | 12 | // ModuleTypeMenu 菜单模块 13 | ModuleTypeMenu // 菜单模块 14 | ) 15 | -------------------------------------------------------------------------------- /pkg/vobj/multidatasourcesustain.go: -------------------------------------------------------------------------------- 1 | package vobj 2 | 3 | // MultiDatasourceSustain 持续类型定义 4 | // 5 | // m时间内出现n次 6 | // m时间内最多出现n次 7 | // m时间内最少出现n次 8 | // 9 | //go:generate go run ../../cmd/server/stringer/cmd.go -type=MultiDatasourceSustain -linecomment 10 | type MultiDatasourceSustain int 11 | 12 | const ( 13 | // MultiDatasourceSustainTypeUnknown 未知 14 | MultiDatasourceSustainTypeUnknown MultiDatasourceSustain = iota // 未知 15 | 16 | // MultiDatasourceSustainTypeAnd 所有数据告警集合一致 17 | MultiDatasourceSustainTypeAnd // 同时满足 所有数据告警集合一致 18 | 19 | // MultiDatasourceSustainTypeOr 其中一个满足 数据告警集合其中一个完全满足 20 | MultiDatasourceSustainTypeOr // 其中一个满足 数据告警集合其中一个完全满足 21 | 22 | // MultiDatasourceSustainTypeAndOr 共同满足 所有数据告警集合合并起来后满足 23 | MultiDatasourceSustainTypeAndOr // 共同满足 所有数据告警集合合并起来后满足 24 | ) 25 | -------------------------------------------------------------------------------- /pkg/vobj/network.go: -------------------------------------------------------------------------------- 1 | package vobj 2 | 3 | import ( 4 | "strings" 5 | ) 6 | 7 | // Network 网络类型 8 | // 9 | //go:generate go run ../../cmd/server/stringer/cmd.go -type=Network -linecomment 10 | type Network int 11 | 12 | const ( 13 | // NetworkUnknown 未知 14 | NetworkUnknown Network = iota // 未知 15 | 16 | // NetworkHTTP http 17 | NetworkHTTP // http 18 | 19 | // NetworkHTTPS https 20 | NetworkHTTPS // https 21 | 22 | // NetworkRPC rpc 23 | NetworkRPC // rpc 24 | ) 25 | 26 | // ToNetwork 获取网络类型 27 | func ToNetwork(s string) Network { 28 | s = strings.ToLower(s) 29 | switch s { 30 | case "http": 31 | return NetworkHTTP 32 | case "https": 33 | return NetworkHTTPS 34 | default: 35 | return NetworkRPC 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /pkg/vobj/oauthapp.go: -------------------------------------------------------------------------------- 1 | package vobj 2 | 3 | // OAuthAPP 系统全局角色 4 | // 5 | //go:generate go run ../../cmd/server/stringer/cmd.go -type=OAuthAPP -linecomment 6 | type OAuthAPP int 7 | 8 | const ( 9 | // OAuthAPPAll 未知 10 | OAuthAPPAll OAuthAPP = iota // 未知 11 | 12 | // OAuthAPPGithub Github 13 | OAuthAPPGithub // Github 14 | 15 | // OAuthAPPGitee Gitee 16 | OAuthAPPGitee // Gitee 17 | // OAuthFeiShu FeiShu 18 | OAuthFeiShu 19 | ) 20 | -------------------------------------------------------------------------------- /pkg/vobj/realtimeaction.go: -------------------------------------------------------------------------------- 1 | package vobj 2 | 3 | // RealTimeAction 实时告警操作类型 4 | // 5 | //go:generate go run ../../cmd/server/stringer/cmd.go -type=RealTimeAction -linecomment 6 | type RealTimeAction int 7 | 8 | const ( 9 | // RealTimeActionUnknown 未知 10 | RealTimeActionUnknown RealTimeAction = iota // 未知 11 | // RealTimeActionMark 标记 12 | RealTimeActionMark // 标记 13 | // RealTimeActionDelete 删除 14 | RealTimeActionDelete // 删除 15 | // RealTimeActionSuppress 抑制 16 | RealTimeActionSuppress // 抑制 17 | // RealTimeActionUpgrade 升级 18 | RealTimeActionUpgrade // 升级 19 | ) 20 | 21 | // EnUSString 英文字符串 22 | func (a RealTimeAction) EnUSString() string { 23 | switch a { 24 | case RealTimeActionMark: 25 | return "mark" 26 | case RealTimeActionDelete: 27 | return "delete" 28 | case RealTimeActionSuppress: 29 | return "suppress" 30 | case RealTimeActionUpgrade: 31 | return "upgrade" 32 | } 33 | return "other" 34 | } 35 | -------------------------------------------------------------------------------- /pkg/vobj/role.go: -------------------------------------------------------------------------------- 1 | package vobj 2 | 3 | // Role 系统全局角色 4 | // 5 | //go:generate go run ../../cmd/server/stringer/cmd.go -type=Role -linecomment 6 | type Role int 7 | 8 | const ( 9 | // RoleAll 未知 10 | RoleAll Role = iota // 未知 11 | 12 | // RoleSuperAdmin 超级管理员 13 | RoleSuperAdmin // 超级管理员 14 | 15 | // RoleAdmin 管理员 16 | RoleAdmin // 管理员 17 | 18 | // RoleUser 普通用户 19 | RoleUser // 普通用户 20 | ) 21 | 22 | // IsAdminOrSuperAdmin 是否是:管理员 | 超级管理员 23 | func (i Role) IsAdminOrSuperAdmin() bool { 24 | return i == RoleAdmin || i == RoleSuperAdmin 25 | } 26 | 27 | // GT 判断是否大于等于 28 | func (i Role) GT(j Role) bool { 29 | return !i.IsAll() && i < j 30 | } 31 | -------------------------------------------------------------------------------- /pkg/vobj/sendstatus.go: -------------------------------------------------------------------------------- 1 | package vobj 2 | 3 | // SendStatus 发送状态 4 | // 5 | //go:generate go run ../../cmd/server/stringer/cmd.go -type=SendStatus -linecomment 6 | type SendStatus int 7 | 8 | const ( 9 | // SendStatusUnknown 未知 10 | SendStatusUnknown SendStatus = iota // 未知 11 | // Sending 发送中 12 | Sending // 发送中 13 | // SentSuccess 发送成功 14 | SentSuccess // 发送成功 15 | // SendFail 发送失败 16 | SendFail // 发送失败 17 | ) 18 | 19 | // EnString 转换为字符串 20 | func (s SendStatus) EnString() string { 21 | switch s { 22 | case Sending: 23 | return "sending" 24 | case SentSuccess: 25 | return "sent_success" 26 | case SendFail: 27 | return "send_fail" 28 | default: 29 | return "unknown" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /pkg/vobj/sendtype.go: -------------------------------------------------------------------------------- 1 | package vobj 2 | 3 | // SendType 发送类型 4 | // 5 | //go:generate go run ../../cmd/server/stringer/cmd.go -type=SendType -linecomment 6 | type SendType int 7 | 8 | const ( 9 | // SendTypeUnknown 未知 10 | SendTypeUnknown SendType = iota // 未知 11 | 12 | // SendTypeInhibit 抑制 13 | SendTypeInhibit // 抑制 14 | 15 | // SendTypeAggregate 聚合 16 | SendTypeAggregate // 聚合 17 | ) 18 | -------------------------------------------------------------------------------- /pkg/vobj/sourcetype.go: -------------------------------------------------------------------------------- 1 | package vobj 2 | 3 | // SourceType 来源类型 4 | // 5 | //go:generate go run ../../cmd/server/stringer/cmd.go -type=SourceType -linecomment 6 | type SourceType int 7 | 8 | const ( 9 | // SourceTypeUnknown 未知 10 | SourceTypeUnknown SourceType = iota // 未知 11 | 12 | // SourceTypeSystem 系统来源 13 | SourceTypeSystem // 系统来源 14 | 15 | // SourceTypeTeam 团队来源 16 | SourceTypeTeam // 团队来源 17 | ) 18 | 19 | const ( 20 | sourceCodeSystem = "System" 21 | sourceCodeTeam = "Team" 22 | ) 23 | 24 | // GetSourceType 根据来源编码获取来源类型 25 | func GetSourceType(sourceCode string) SourceType { 26 | switch sourceCode { 27 | case sourceCodeSystem: 28 | return SourceTypeSystem 29 | case sourceCodeTeam: 30 | return SourceTypeTeam 31 | default: 32 | return SourceTypeTeam 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /pkg/vobj/status.go: -------------------------------------------------------------------------------- 1 | package vobj 2 | 3 | // Status 数据状态 4 | // 5 | //go:generate go run ../../cmd/server/stringer/cmd.go -type=Status -linecomment 6 | type Status int 7 | 8 | const ( 9 | // StatusUnknown 未知 10 | StatusUnknown Status = iota // 未知 11 | 12 | // StatusEnable 启用 13 | StatusEnable // 启用 14 | 15 | // StatusDisable 禁用 16 | StatusDisable // 禁用 17 | ) 18 | -------------------------------------------------------------------------------- /pkg/vobj/storagetype.go: -------------------------------------------------------------------------------- 1 | package vobj 2 | 3 | // StorageType 存储类型 4 | // 5 | //go:generate go run ../../cmd/server/stringer/cmd.go -type=StorageType -linecomment 6 | type StorageType int 7 | 8 | const ( 9 | // StorageTypeUnknown 未知 10 | StorageTypeUnknown StorageType = iota // 未知 11 | 12 | // StorageTypePrometheus Prometheus 13 | StorageTypePrometheus // Prometheus 14 | 15 | // StorageTypeVictoriametrics VictoriaMetrics 16 | StorageTypeVictoriametrics // VictoriaMetrics 17 | 18 | StorageTypeElasticsearch // Elasticsearch 19 | StorageTypeLoki // Loki 20 | 21 | StorageAliYunSLS // AliYunSLS 22 | ) 23 | 24 | const ( 25 | // StorageTypeKafka Kafka 26 | StorageTypeKafka StorageType = iota + 10 // Kafka 27 | 28 | // StorageTypeRabbitMQ RabbitMQ 29 | StorageTypeRabbitMQ // RabbitMQ 30 | 31 | // StorageTypeRocketMQ RocketMQ 32 | StorageTypeRocketMQ // RocketMQ 33 | 34 | // StorageTypeMQTT MQTT 35 | StorageTypeMQTT // MQTT 36 | ) 37 | -------------------------------------------------------------------------------- /pkg/vobj/strategytemplatesource.go: -------------------------------------------------------------------------------- 1 | package vobj 2 | 3 | // StrategyTemplateSource 消息类型 4 | // 5 | //go:generate go run ../../cmd/server/stringer/cmd.go -type=StrategyTemplateSource -linecomment 6 | type StrategyTemplateSource int 7 | 8 | const ( 9 | // StrategyTemplateSourceUnknown 未知 10 | StrategyTemplateSourceUnknown StrategyTemplateSource = iota // 未知 11 | 12 | // StrategyTemplateSourceSystem 系统来源 13 | StrategyTemplateSourceSystem // 系统来源 14 | 15 | // StrategyTemplateSourceTeam 团队来源 16 | StrategyTemplateSourceTeam // 团队来源 17 | ) 18 | -------------------------------------------------------------------------------- /pkg/vobj/strategytype.go: -------------------------------------------------------------------------------- 1 | package vobj 2 | 3 | // StrategyType 策略类型 4 | // 5 | //go:generate go run ../../cmd/server/stringer/cmd.go -type=StrategyType -linecomment 6 | type StrategyType int 7 | 8 | const ( 9 | // StrategyTypeUnknown 未知 10 | StrategyTypeUnknown StrategyType = iota // unknown 11 | 12 | // StrategyTypeMetric 指标策略 13 | StrategyTypeMetric // metric 14 | 15 | // StrategyTypeDomainCertificate 域名证书策略 16 | StrategyTypeDomainCertificate // domain_certificate 17 | 18 | // StrategyTypeDomainPort 域名端口策略 19 | StrategyTypeDomainPort // domain_port 20 | 21 | // StrategyTypePing 网络连通性策略 22 | StrategyTypePing // ping 23 | 24 | // StrategyTypeHTTP 网站可用性策略 25 | StrategyTypeHTTP // http 26 | 27 | // StrategyTypeEvent 事件策略 28 | StrategyTypeEvent // event 29 | 30 | // StrategyTypeLogs 日志策略 31 | StrategyTypeLogs // log 32 | ) 33 | -------------------------------------------------------------------------------- /pkg/vobj/topic.go: -------------------------------------------------------------------------------- 1 | package vobj 2 | 3 | // Topic 消息类型 4 | // 5 | //go:generate go run ../../cmd/server/stringer/cmd.go -type=Topic -linecomment 6 | type Topic int 7 | 8 | const ( 9 | // TopicUnknown 未知 10 | TopicUnknown Topic = iota // 未知 11 | 12 | // TopicStrategy 策略 13 | TopicStrategy // 策略 14 | 15 | // TopicAlert 单条告警 16 | TopicAlert // 单条告警 17 | 18 | // TopicAlarm 多条告警 19 | TopicAlarm // 多条告警 20 | 21 | // TopicAlertMsg 告警消息 22 | TopicAlertMsg // 告警消息 23 | 24 | // TopicEventDatasource MQ 数据源 25 | TopicEventDatasource // MQ 数据源 26 | 27 | // TopicEventStrategy 事件策略 28 | TopicEventStrategy // 事件策略 29 | ) 30 | -------------------------------------------------------------------------------- /pkg/vobj/usermessagetype.go: -------------------------------------------------------------------------------- 1 | package vobj 2 | 3 | // UserMessageType 用户消息类型 4 | // 5 | //go:generate go run ../../cmd/server/stringer/cmd.go -type=UserMessageType -linecomment 6 | type UserMessageType int 7 | 8 | const ( 9 | // UserMessageTypeUnknown 未知 10 | UserMessageTypeUnknown UserMessageType = iota // unknown 11 | 12 | // UserMessageTypeInfo 信息 13 | UserMessageTypeInfo // info 14 | 15 | // UserMessageTypeWarning 警告 16 | UserMessageTypeWarning // warning 17 | 18 | // UserMessageTypeError 错误 19 | UserMessageTypeError // error 20 | 21 | // UserMessageTypeSuccess 成功 22 | UserMessageTypeSuccess // success 23 | ) 24 | -------------------------------------------------------------------------------- /pkg/watch/metric.go: -------------------------------------------------------------------------------- 1 | package watch 2 | 3 | import ( 4 | "github.com/prometheus/client_golang/prometheus" 5 | ) 6 | 7 | var ( 8 | watchQueueMetric = prometheus.NewGaugeVec(prometheus.GaugeOpts{ 9 | Name: "watch_queue_size", 10 | Help: "The size of the watch queue", 11 | }, []string{"name"}) 12 | 13 | watchStorageMetric = prometheus.NewGaugeVec(prometheus.GaugeOpts{ 14 | Name: "watch_storage_size", 15 | Help: "The size of the watch storage", 16 | }, []string{"name"}) 17 | ) 18 | 19 | func init() { 20 | prometheus.MustRegister(watchQueueMetric) 21 | prometheus.MustRegister(watchStorageMetric) 22 | } 23 | 24 | func updateWatchQueueMetric(name string, size int) { 25 | watchQueueMetric.WithLabelValues(name).Set(float64(size)) 26 | } 27 | 28 | func updateWatchStorageMetric(name string, size int) { 29 | watchStorageMetric.WithLabelValues(name).Set(float64(size)) 30 | } 31 | -------------------------------------------------------------------------------- /pkg/watch/queue.go: -------------------------------------------------------------------------------- 1 | package watch 2 | 3 | // QueueMaxSize 默认消息队列最大长度 4 | const QueueMaxSize = 1 << 10 5 | 6 | // NewDefaultQueue 定义接收消息和发送消息的消息队列 7 | func NewDefaultQueue(size int) Queue { 8 | return &defaultQueue{ 9 | queue: make(chan *Message, size), 10 | } 11 | } 12 | 13 | type ( 14 | // Queue 消息队列 15 | Queue interface { 16 | // Next 获取下一个消息 17 | Next() <-chan *Message 18 | 19 | // Push 添加消息 20 | Push(msg *Message) error 21 | 22 | // Close 关闭队列 23 | Close() error 24 | 25 | // Len 获取队列长度 26 | Len() int 27 | 28 | // Clear 清空队列 29 | Clear() 30 | } 31 | 32 | // defaultQueue 默认消息队列 33 | defaultQueue struct { 34 | queue chan *Message 35 | maxSize int 36 | } 37 | ) 38 | 39 | func (d *defaultQueue) Next() <-chan *Message { 40 | return d.queue 41 | } 42 | 43 | func (d *defaultQueue) Push(msg *Message) error { 44 | d.queue <- msg 45 | return nil 46 | } 47 | 48 | func (d *defaultQueue) Close() error { 49 | close(d.queue) 50 | return nil 51 | } 52 | 53 | func (d *defaultQueue) Len() int { 54 | return len(d.queue) 55 | } 56 | 57 | func (d *defaultQueue) Clear() { 58 | d.queue = make(chan *Message, d.maxSize) 59 | } 60 | -------------------------------------------------------------------------------- /pr.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | git fetch origin pull/$1/head:pr/$1 && git checkout pr/$1 --no-pager 2> /dev/null || git branch -r | grep $1 3 | git checkout pr/$1 -------------------------------------------------------------------------------- /third_party/README.md: -------------------------------------------------------------------------------- 1 | # third_party 2 | -------------------------------------------------------------------------------- /third_party/errors/errors.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package errors; 4 | 5 | option go_package = "github.com/go-kratos/kratos/v2/errors;errors"; 6 | option java_multiple_files = true; 7 | option java_package = "com.github.kratos.errors"; 8 | option objc_class_prefix = "KratosErrors"; 9 | 10 | import "google/protobuf/descriptor.proto"; 11 | 12 | extend google.protobuf.EnumOptions { 13 | int32 default_code = 1108; 14 | } 15 | 16 | message Metadata { 17 | string key = 1; 18 | string value = 2; 19 | string defaultValue = 3; 20 | } 21 | 22 | message BizReason { 23 | string reason = 1; 24 | string message = 2; 25 | repeated Metadata metadata = 3; 26 | } 27 | 28 | extend google.protobuf.EnumValueOptions { 29 | int32 code = 1109; 30 | string message = 1110; 31 | string id = 1111; 32 | repeated Metadata metadata = 1112; 33 | repeated BizReason biz_reason = 1113; 34 | } 35 | -------------------------------------------------------------------------------- /third_party/google/api/annotations.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.api; 18 | 19 | import "google/api/http.proto"; 20 | import "google/protobuf/descriptor.proto"; 21 | 22 | option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; 23 | option java_multiple_files = true; 24 | option java_outer_classname = "AnnotationsProto"; 25 | option java_package = "com.google.api"; 26 | option objc_class_prefix = "GAPI"; 27 | 28 | extend google.protobuf.MethodOptions { 29 | // See `HttpRule`. 30 | HttpRule http = 72295728; 31 | } 32 | -------------------------------------------------------------------------------- /third_party/swagger_ui/.gitignore: -------------------------------------------------------------------------------- 1 | openapi.yaml --------------------------------------------------------------------------------