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.

sync_user_group.go 5.9 kB

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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. package flashduty
  2. import (
  3. "errors"
  4. "strconv"
  5. "strings"
  6. "github.com/ccfos/nightingale/v6/models"
  7. "github.com/ccfos/nightingale/v6/pkg/ctx"
  8. "github.com/toolkits/pkg/logger"
  9. )
  10. type UserGroupSyncer struct {
  11. ctx *ctx.Context
  12. ug *models.UserGroup
  13. appKey string
  14. teamID int64
  15. }
  16. func NewUserGroupSyncer(ctx *ctx.Context, ug *models.UserGroup) (*UserGroupSyncer, error) {
  17. appKey, err := models.ConfigsGetFlashDutyAppKey(ctx)
  18. if err != nil {
  19. return nil, err
  20. }
  21. return &UserGroupSyncer{
  22. ctx: ctx,
  23. ug: ug,
  24. appKey: appKey,
  25. }, nil
  26. }
  27. func (ugs *UserGroupSyncer) SyncUGAdd() error {
  28. // 新建团队(无用户仅有团队名称)
  29. fdt := Team{
  30. TeamName: ugs.ug.Name,
  31. RefID: strconv.FormatInt(ugs.ug.Id, 10),
  32. }
  33. err := fdt.UpdateTeam(ugs.appKey)
  34. if err != nil {
  35. return err
  36. }
  37. return ugs.syncTeamMember()
  38. }
  39. func (ugs *UserGroupSyncer) SyncUGPut() error {
  40. // 修改为查询 ref_ID
  41. refID := strconv.FormatInt(ugs.ug.Id, 10)
  42. teamID, err := ugs.CheckTeam(refID)
  43. // 如果没有找到团队,说明是新建的团队
  44. ugs.teamID = teamID
  45. if err != nil && strings.Contains(err.Error(), "no team found by ref_id") {
  46. emails := make([]string, 0)
  47. phones := make([]string, 0)
  48. for _, user := range ugs.ug.Users {
  49. if user.Email != "" {
  50. emails = append(emails, user.Email)
  51. } else if user.Phone != "" {
  52. phones = append(phones, user.Phone)
  53. } else {
  54. logger.Warningf("The user %s has no email and phone, and failed to sync to flashduty's team", user.Username)
  55. }
  56. }
  57. //根据 team_id 去更新 duty 中这个团队的信息
  58. fdt := Team{
  59. RefID: refID,
  60. TeamName: ugs.ug.Name,
  61. Emails: emails,
  62. Phones: phones,
  63. }
  64. if err := fdt.AddTeam(ugs.appKey); err != nil {
  65. return err
  66. }
  67. if err := ugs.syncTeamMember(); err != nil {
  68. return err
  69. }
  70. return nil
  71. }
  72. if err != nil {
  73. return err
  74. }
  75. emails := make([]string, 0)
  76. phones := make([]string, 0)
  77. for _, user := range ugs.ug.Users {
  78. if user.Email != "" {
  79. emails = append(emails, user.Email)
  80. } else if user.Phone != "" {
  81. phones = append(phones, user.Phone)
  82. } else {
  83. logger.Warningf("The user %s has no email and phone, and failed to sync to flashduty's team", user.Username)
  84. }
  85. }
  86. //根据 team_id 去更新 duty 中这个团队的信息
  87. fdt := Team{
  88. TeamID: teamID,
  89. RefID: refID,
  90. TeamName: ugs.ug.Name,
  91. Emails: emails,
  92. Phones: phones,
  93. }
  94. if err := fdt.UpdateTeam(ugs.appKey); err != nil {
  95. return err
  96. }
  97. if err := ugs.syncTeamMember(); err != nil {
  98. return err
  99. }
  100. return nil
  101. }
  102. func (ugs *UserGroupSyncer) SyncUGDel() error {
  103. fdt := Team{
  104. RefID: strconv.FormatInt(ugs.ug.Id, 10),
  105. }
  106. err := fdt.DelTeam(ugs.appKey)
  107. return err
  108. }
  109. func (ugs *UserGroupSyncer) SyncMembersAdd() error {
  110. return ugs.syncTeamMember()
  111. }
  112. func (ugs *UserGroupSyncer) SyncMembersDel() error {
  113. return ugs.syncTeamMember()
  114. }
  115. func (ugs *UserGroupSyncer) syncTeamMember() error {
  116. uids, err := models.MemberIds(ugs.ctx, ugs.ug.Id)
  117. if err != nil {
  118. return err
  119. }
  120. users, err := models.UserGetsByIds(ugs.ctx, uids)
  121. if err != nil {
  122. return err
  123. }
  124. toDutyErr := ugs.addMemberToFDTeam(users)
  125. if toDutyErr != nil {
  126. logger.Warningf("failed to sync user group %s %v to flashduty's team: %v", ugs.ug.Name, users, toDutyErr)
  127. }
  128. return err
  129. }
  130. func (ugs *UserGroupSyncer) addMemberToFDTeam(users []models.User) error {
  131. if err := fdAddUsers(ugs.appKey, users); err != nil {
  132. return err
  133. }
  134. emails := make([]string, 0)
  135. phones := make([]string, 0)
  136. for _, user := range users {
  137. if user.Email != "" {
  138. emails = append(emails, user.Email)
  139. } else if user.Phone != "" {
  140. phones = append(phones, user.Phone)
  141. } else {
  142. logger.Warningf("The user %s has no email and phone, and failed to sync to flashduty's team", user.Username)
  143. }
  144. }
  145. teamID := ugs.teamID
  146. refID := strconv.FormatInt(ugs.ug.Id, 10)
  147. var err error
  148. if teamID == 0 {
  149. teamID, err = ugs.CheckTeam(refID)
  150. if err != nil {
  151. logger.Warningf("CheckTeam failed for refID=%v: %v", refID, err)
  152. }
  153. }
  154. fdt := Team{
  155. TeamID: teamID,
  156. TeamName: ugs.ug.Name,
  157. Emails: emails,
  158. Phones: phones,
  159. RefID: refID,
  160. }
  161. err = fdt.UpdateTeam(ugs.appKey)
  162. return err
  163. }
  164. type Team struct {
  165. TeamID int64 `json:"team_id"`
  166. TeamName string `json:"team_name"`
  167. ResetIfNameExist bool `json:"reset_if_name_exist"`
  168. Description string `json:"description"`
  169. Emails []string `json:"emails"`
  170. Phones []string `json:"phones"`
  171. RefID string `json:"ref_id"`
  172. }
  173. func (t *Team) AddTeam(appKey string) error {
  174. if t.TeamName == "" {
  175. return errors.New("team_name must be set")
  176. }
  177. return PostFlashDuty("/team/upsert", appKey, t)
  178. }
  179. func (t *Team) UpdateTeam(appKey string) error {
  180. t.ResetIfNameExist = true
  181. err := t.AddTeam(appKey)
  182. return err
  183. }
  184. func (t *Team) DelTeam(appKey string) error {
  185. err := PostFlashDuty("/team/delete", appKey, t)
  186. return err
  187. }
  188. func NeedSyncTeam(ctx *ctx.Context) bool {
  189. configs, err := models.ConfigsSelectByCkey(ctx, "flashduty_sync_team")
  190. if err != nil {
  191. logger.Warningf("failed to query flashduty_sync_team: %v", err)
  192. return false
  193. }
  194. if len(configs) == 0 || configs[0].Cval == "" {
  195. return false
  196. }
  197. return configs[0].Cval == "true"
  198. }
  199. func NeedSyncUser(ctx *ctx.Context) bool {
  200. configs, err := models.ConfigsSelectByCkey(ctx, "flashduty_app_key")
  201. if err != nil {
  202. logger.Warningf("failed to query flashduty_app_key: %v", err)
  203. return false
  204. }
  205. if len(configs) == 0 || configs[0].Cval == "" {
  206. return false
  207. }
  208. return true
  209. }
  210. // CheckTeam 检查ref_id是否存在
  211. func (ugs *UserGroupSyncer) CheckTeam(ref_id string) (int64, error) {
  212. // Construct the request to query the team by name
  213. info, err := PostFlashDutyWithResp[TeamInfo]("/team/info", ugs.appKey, map[string]interface{}{
  214. "ref_id": ref_id,
  215. })
  216. if err != nil || info.TeamID == 0 {
  217. return 0, err
  218. }
  219. return info.TeamID, nil
  220. }