You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

post.go 909 B

feat: sync user and user_group to flashduty (#1842) * fix build event * fix: append labels * Add the function of batch subscription alert rules (#1825) * add: docker-compose files for logs processing * update: set restart:always * fix: compose-host-network-metric-log * update: regularize * add: batch subscription * add: sql columns for rule_ids and rule_names * add: add migrate of AlertSubscribe * update: Remove redundant codes * fix: The question of 1821 * fix: Optimized for getting rule_ids and rule_names * fix: error handle * fix: add rule_ids for update api * fix: Clear the rule_id to zero when updating * refactor: Compatible with old rule_id * refactor: rename * fix: set rule_id=0 when updating subscription rules --------- Co-authored-by: wdk <wdk_cc@163.com> * feat: sync user and team to flashduty * fix: sync to flashduty * fix: failed to update team change to flashduty * fix: sync default user when create team * chore: delete the generated binary file * refactor: user_group refact * fix: func AddUsers(fdConf *cconf.FlashDuty, appKey string, users []User) error { * fix: remove sync for user in router * fix: user_grroup no change in n9e when put user_group * chore: set default api_url=https://api.flashcat.cloud * chore: refactor user_group * chore: refact codes * chore: set api=https://jira.flashcat.cloud/api for test * chore: set api=https://api.flashcat.cloud * chore: adjust the import order * chore: remove excess code * chore: refact codes * chore: remove excess codes * chore: adjust import order * chore: adjust import order * chore: adjust import order * chore: refact code * chore: optimized codes * code refactor * chore: remove excess code --------- Co-authored-by: ning <710leo@gmail.com> Co-authored-by: wdk <wdk_cc@163.com>
2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940
  1. package flashduty
  2. import (
  3. "fmt"
  4. "net/url"
  5. "time"
  6. "github.com/ccfos/nightingale/v6/center/cconf"
  7. "github.com/ccfos/nightingale/v6/pkg/poster"
  8. "github.com/toolkits/pkg/logger"
  9. )
  10. var (
  11. Api string
  12. Timeout time.Duration
  13. )
  14. func Init(fdConf cconf.FlashDuty) {
  15. Api = fdConf.Api
  16. if fdConf.Timeout == 0 {
  17. Timeout = 5 * time.Second
  18. } else {
  19. Timeout = fdConf.Timeout * time.Millisecond
  20. }
  21. }
  22. func PostFlashDuty(path string, appKey string, body interface{}) error {
  23. urlParams := url.Values{}
  24. urlParams.Add("app_key", appKey)
  25. var url string
  26. if Api != "" {
  27. url = fmt.Sprintf("%s%s?%s", Api, path, urlParams.Encode())
  28. } else {
  29. url = fmt.Sprintf("%s%s?%s", "https://api.flashcat.cloud", path, urlParams.Encode())
  30. }
  31. response, code, err := poster.PostJSON(url, Timeout, body)
  32. logger.Infof("exec PostFlashDuty: url=%s, body=%v; response=%s, code=%d", url, body, response, code)
  33. return err
  34. }