crash.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. Copyright 2021 The Rook Authors. All rights reserved.
  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. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package client
  14. import (
  15. "encoding/json"
  16. "github.com/pkg/errors"
  17. "github.com/rook/rook/pkg/clusterd"
  18. )
  19. // CrashList is go representation of the "ceph crash ls" command output
  20. type CrashList struct {
  21. ID string `json:"crash_id"`
  22. Entity string `json:"entity_name"`
  23. Timestamp string `json:"timestamp"`
  24. ProcessName string `json:"process_name,omitempty"`
  25. CephVersion string `json:"ceph_version,omitempty"`
  26. UtsnameHostname string `json:"utsname_hostname,omitempty"`
  27. UtsnameSysname string `json:"utsname_sysname,omitempty"`
  28. UtsnameRelease string `json:"utsname_release,omitempty"`
  29. UtsnameVersion string `json:"utsname_version,omitempty"`
  30. UtsnameMachine string `json:"utsname_machine,omitempty"`
  31. OsName string `json:"os_name,omitempty"`
  32. OsID string `json:"os_id,omitempty"`
  33. OsVersionID string `json:"os_version_id,omitempty"`
  34. OsVersion string `json:"os_version,omitempty"`
  35. AssertCondition string `json:"assert_condition,omitempty"`
  36. AssertFunc string `json:"assert_func,omitempty"`
  37. AssertLine int `json:"assert_line,omitempty"`
  38. AssertFile string `json:"assert_file,omitempty"`
  39. AssertThreadName string `json:"assert_thread_name,omitempty"`
  40. AssertMsg string `json:"assert_msg,omitempty"`
  41. IoError bool `json:"io_error,omitempty"`
  42. IoErrorDevname string `json:"io_error_devname,omitempty"`
  43. IoErrorPath string `json:"io_error_path,omitempty"`
  44. IoErrorCode int `json:"io_error_code,omitempty"`
  45. IoErrorOptype int `json:"io_error_optype,omitempty"`
  46. IoErrorOffset int `json:"io_error_offset,omitempty"`
  47. IoErrorLength int `json:"iio_error_length,omitempty"`
  48. Backtrace []string `json:"backtrace,omitempty"`
  49. }
  50. // GetCrashList gets the list of Crashes.
  51. func GetCrashList(context *clusterd.Context, clusterInfo *ClusterInfo) ([]CrashList, error) {
  52. crashArgs := []string{"crash", "ls"}
  53. output, err := NewCephCommand(context, clusterInfo, crashArgs).Run()
  54. if err != nil {
  55. return nil, errors.Wrap(err, "failed to list ceph crash")
  56. }
  57. var crash []CrashList
  58. err = json.Unmarshal(output, &crash)
  59. if err != nil {
  60. return nil, errors.Wrapf(err, "failed to unmarshal crash ls response. %s", string(output))
  61. }
  62. return crash, err
  63. }
  64. // ArchiveCrash archives the crash with respective crashID
  65. func ArchiveCrash(context *clusterd.Context, clusterInfo *ClusterInfo, crashID string) error {
  66. logger.Infof("silencing crash %q", crashID)
  67. crashSilenceArgs := []string{"crash", "archive", crashID}
  68. _, err := NewCephCommand(context, clusterInfo, crashSilenceArgs).Run()
  69. if err != nil {
  70. return errors.Wrapf(err, "failed to archive crash %q", crashID)
  71. }
  72. logger.Infof("successfully silenced crash %q", crashID)
  73. return nil
  74. }
  75. // GetCrash gets the crash list
  76. func GetCrash(context *clusterd.Context, clusterInfo *ClusterInfo) ([]CrashList, error) {
  77. crash, err := GetCrashList(context, clusterInfo)
  78. if err != nil {
  79. return nil, errors.Wrap(err, "failed to list ceph crash")
  80. }
  81. return crash, nil
  82. }