event.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 k8s
  15. import (
  16. "fmt"
  17. "yunion.io/x/jsonutils"
  18. "yunion.io/x/onecloud/pkg/mcclient/modules"
  19. )
  20. var (
  21. Logs *ResourceManager
  22. Events *EventManager
  23. )
  24. type EventManager struct {
  25. *NamespaceResourceManager
  26. }
  27. func init() {
  28. Logs = NewResourceManager("event", "events",
  29. NewColumns("id", "ops_time", "obj_id", "obj_type", "obj_name", "user", "user_id", "tenant", "tenant_id", "owner_tenant_id", "action", "notes"),
  30. NewColumns())
  31. Events = &EventManager{
  32. NamespaceResourceManager: NewNamespaceResourceManager("k8s_event", "k8s_events",
  33. NewNamespaceCols("Source", "Type", "Action", "Object", "Message"),
  34. NewColumns()),
  35. }
  36. modules.Register(Events)
  37. }
  38. func (m EventManager) Get_Source(obj jsonutils.JSONObject) interface{} {
  39. src, _ := obj.GetString("source")
  40. return src
  41. }
  42. func (m EventManager) Get_Type(obj jsonutils.JSONObject) interface{} {
  43. typ, _ := obj.GetString("type")
  44. return typ
  45. }
  46. func (m EventManager) Get_Action(obj jsonutils.JSONObject) interface{} {
  47. act, _ := obj.Get("action")
  48. return act
  49. }
  50. func (m EventManager) Get_Object(obj jsonutils.JSONObject) interface{} {
  51. refObj, _ := obj.Get("involvedObject")
  52. if refObj == nil {
  53. return ""
  54. }
  55. kind, _ := refObj.GetString("kind")
  56. name, _ := refObj.GetString("name")
  57. return fmt.Sprintf("%s/%s", kind, name)
  58. }
  59. func (m EventManager) Get_Message(obj jsonutils.JSONObject) interface{} {
  60. msg, _ := obj.GetString("message")
  61. return msg
  62. }