options.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2019 Yunion
  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. package options
  15. import (
  16. common_options "yunion.io/x/onecloud/pkg/cloudcommon/options"
  17. "yunion.io/x/onecloud/pkg/logger/extern"
  18. )
  19. type SLoggerOptions struct {
  20. common_options.CommonOptions
  21. common_options.DBOptions
  22. SyslogUrl string `help:"external syslog url, e.g. tcp://localhost:1234@cloud"`
  23. EnableSeparateAdminLog bool `help:"enable separate log for auditor admin" default:"false"`
  24. SecadminRoleNames []string `help:"role names of security admin" default:"sys_secadmin,domain_secadmin"`
  25. OpsadminRoleNames []string `help:"role names of operation admin" default:"sys_opsadmin,domain_opsadmin"`
  26. AuditorRoleNames []string `help:"role names of auditor admin" default:"sys_adtadmin,domain_adtadmin"`
  27. ActionLogExceedCount int `help:"trigger notification when action log exceed count" default:"-1"`
  28. ActionLogExceedCountNotifyInterval string `help:"trigger notification interval" default:"5m"`
  29. SyslogVendorCode string `help:"vendor code of syslog" default:"0003"`
  30. SyslogSeparator string `help:"syslog message field separator" default:","`
  31. SyslogSepEscape string `help:"syslog message separate escape string" default:"+"`
  32. }
  33. var (
  34. Options SLoggerOptions
  35. )
  36. func OnOptionsChange(oldOptions, newOptions interface{}) bool {
  37. oldOpts := oldOptions.(*SLoggerOptions)
  38. newOpts := newOptions.(*SLoggerOptions)
  39. changed := false
  40. if common_options.OnBaseOptionsChange(&oldOpts.BaseOptions, &newOpts.BaseOptions) {
  41. changed = true
  42. }
  43. if common_options.OnDBOptionsChange(&oldOpts.DBOptions, &newOpts.DBOptions) {
  44. changed = true
  45. }
  46. if oldOpts.SyslogUrl != newOpts.SyslogUrl {
  47. err := extern.InitSyslog(newOpts.SyslogUrl)
  48. if err != nil {
  49. // reset syslog writer error, restart the service to take effect
  50. changed = true
  51. }
  52. }
  53. return changed
  54. }