mod_logs.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 modules
  15. import (
  16. "yunion.io/x/jsonutils"
  17. "yunion.io/x/onecloud/pkg/apis"
  18. "yunion.io/x/onecloud/pkg/mcclient"
  19. "yunion.io/x/onecloud/pkg/mcclient/modulebase"
  20. )
  21. type LogsManager struct {
  22. modulebase.ResourceManager
  23. }
  24. var (
  25. Logs LogsManager
  26. IdentityLogs modulebase.ResourceManager
  27. ImageLogs modulebase.ResourceManager
  28. ActionLogs modulebase.ResourceManager
  29. CloudeventLogs modulebase.ResourceManager
  30. ComputeLogs modulebase.ResourceManager
  31. DmesgLogs modulebase.ResourceManager
  32. MonitorLogs modulebase.ResourceManager
  33. NotifyLogs modulebase.ResourceManager
  34. )
  35. func (this *LogsManager) Get(session *mcclient.ClientSession, id string, params jsonutils.JSONObject) (jsonutils.JSONObject, error) {
  36. service, _ := params.GetString("service")
  37. switch service {
  38. case apis.SERVICE_TYPE_LOG:
  39. return ActionLogs.Get(session, id, params)
  40. case apis.SERVICE_TYPE_IMAGE:
  41. return ImageLogs.Get(session, id, params)
  42. case apis.SERVICE_TYPE_KEYSTONE:
  43. return IdentityLogs.Get(session, id, params)
  44. case apis.SERVICE_TYPE_CLOUDEVENT:
  45. return CloudeventLogs.Get(session, id, params)
  46. case apis.SERVICE_TYPE_MONITOR:
  47. return MonitorLogs.Get(session, id, params)
  48. case apis.SERVICE_TYPE_NOTIFY:
  49. return NotifyLogs.Get(session, id, params)
  50. default:
  51. return ComputeLogs.Get(session, id, params)
  52. }
  53. }
  54. func (this *LogsManager) PerformClassAction(session *mcclient.ClientSession, action string, params jsonutils.JSONObject) (jsonutils.JSONObject, error) {
  55. service, _ := params.GetString("service")
  56. switch service {
  57. case apis.SERVICE_TYPE_LOG:
  58. return ActionLogs.PerformClassAction(session, action, params)
  59. case apis.SERVICE_TYPE_IMAGE:
  60. return ImageLogs.PerformClassAction(session, action, params)
  61. case apis.SERVICE_TYPE_KEYSTONE:
  62. return IdentityLogs.PerformClassAction(session, action, params)
  63. case apis.SERVICE_TYPE_CLOUDEVENT:
  64. return CloudeventLogs.PerformClassAction(session, action, params)
  65. case apis.SERVICE_TYPE_MONITOR:
  66. return MonitorLogs.PerformClassAction(session, action, params)
  67. case apis.SERVICE_TYPE_NOTIFY:
  68. return NotifyLogs.PerformClassAction(session, action, params)
  69. default:
  70. return ComputeLogs.PerformClassAction(session, action, params)
  71. }
  72. }
  73. func init() {
  74. IdentityLogs = NewIdentityV3Manager("event", "events",
  75. []string{"id", "ops_time", "obj_id", "obj_type", "obj_name", "user", "user_id", "tenant", "tenant_id", "owner_tenant_id", "action", "notes"},
  76. []string{})
  77. ImageLogs = NewImageManager("event", "events",
  78. []string{"id", "ops_time", "obj_id", "obj_type", "obj_name", "user", "user_id", "tenant", "tenant_id", "owner_tenant_id", "action", "notes"},
  79. []string{})
  80. ActionLogs = NewActionManager("event", "events",
  81. []string{"id", "ops_time", "obj_id", "obj_type", "obj_name", "user", "user_id", "tenant", "tenant_id", "owner_tenant_id", "action", "notes"},
  82. []string{})
  83. CloudeventLogs = NewCloudeventManager("event", "events",
  84. []string{"id", "ops_time", "obj_id", "obj_type", "obj_name", "user", "user_id", "tenant", "tenant_id", "owner_tenant_id", "action", "notes"},
  85. []string{})
  86. ComputeLogs = NewComputeManager("event", "events",
  87. []string{"id", "ops_time", "obj_id", "obj_type", "obj_name", "user", "user_id", "tenant", "tenant_id", "owner_tenant_id", "action", "notes"},
  88. []string{})
  89. DmesgLogs = NewComputeManager("hostdmesg", "hostdmesgs",
  90. []string{"id", "ops_time", "log_level", "obj_id", "obj_name", "user", "user_id", "tenant", "tenant_id", "owner_tenant_id", "notes"},
  91. []string{})
  92. // ComputeLogs.SetApiVersion(mcclient.V2_API_VERSION)
  93. MonitorLogs = NewMonitorV2Manager("event", "events",
  94. []string{"id", "ops_time", "obj_id", "obj_type", "obj_name", "user", "tenant", "action", "notes"},
  95. []string{})
  96. NotifyLogs = NewNotifyv2Manager("event", "events",
  97. []string{"id", "ops_time", "obj_id", "obj_type", "obj_name", "user", "tenant", "action", "notes"},
  98. []string{})
  99. Logs = LogsManager{ComputeLogs}
  100. Register(&Logs)
  101. Register(&DmesgLogs)
  102. }