bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/cmd/bosun/web/static/js/models.ts (about)

     1  /// <reference path="moment.d.ts" />
     2  /// <reference path="moment-duration-format.d.ts" />
     3  
     4  //Represents an auth token
     5  class Token {
     6      public Hash: string;
     7      public Description: string = "";
     8      public Role: number = 0;
     9      public User: string = "";
    10      public LastUsed: Moment;
    11  
    12      public Permissions: string[];
    13      public RoleName: string;
    14  }
    15  
    16  //metadata about a single role or permission
    17  class BitMeta {
    18      public Bits: number;
    19      public Name: string;
    20      public Desc: string;
    21      public Active: boolean;
    22  }
    23  
    24  //all roles/permissions for bosun
    25  class RoleDefs {
    26      public Permissions: Array<BitMeta>;
    27      public Roles: Array<BitMeta>;
    28  }
    29  
    30  // See models/incident.go Event (can't be event here because JS uses that)
    31  class IncidentEvent {
    32      // Embedded properties of Result struct
    33      Value: number;
    34      Expr: string;
    35      Status: number;
    36      Time: string; // moment?
    37      Unevaluated: boolean;
    38  
    39      constructor(ie) {
    40          this.Value = ie.Value;
    41          this.Expr = ie.Expr;
    42          this.Status = ie.Status;
    43          this.Time = ie.Time;
    44          this.Unevaluated = ie.Unevaluated;
    45      }
    46  }
    47  
    48  class Annotation {
    49      Id: string;
    50      Message: string;
    51      StartDate: string; // RFC3999
    52      EndDate: string; // RFC3999
    53      CreationUser: string;
    54      Url: string;
    55      Source: string;
    56      Host: string;
    57      Owner: string;
    58      Category: string;
    59  
    60      constructor(a?, get?: boolean) {
    61          a = a || {};
    62          this.Id = a.Id || "";
    63          this.Message = a.Message || "";
    64          this.StartDate = a.StartDate || "";
    65          this.EndDate = a.EndDate || "";
    66          this.CreationUser = a.CreationUser || "";
    67          this.Url = a.Url || "";
    68          this.Source = a.Source || "bosun-ui";
    69          this.Host = a.Host || "";
    70          this.Owner = a.Owner || !get && getOwner() || "";
    71          this.Category = a.Category || "";
    72      }
    73      setTimeUTC() {
    74          var now = moment().utc().format(timeFormat)
    75          this.StartDate = now;
    76          this.EndDate = now;
    77      }
    78      setTime() {
    79          var now = moment().format(timeFormat)
    80          this.StartDate = now;
    81          this.EndDate = now;
    82      }
    83  }
    84  
    85  class Result {
    86      Value: number;
    87      Expr: string;
    88  
    89      constructor(r) {
    90          this.Value = r.Value;
    91          this.Expr = r.Expr;
    92      }
    93  }
    94  
    95  class Action {
    96      User: string;
    97      Message: string;
    98      Time: string; // moment?
    99      Type: string;
   100      Deadline: string; // moment?
   101      Fullfilled: boolean;
   102      Cancelled: boolean;
   103  
   104      constructor(a) {
   105          this.User = a.User;
   106          this.Message = a.Message;
   107          this.Time = a.Time;
   108          this.Type = a.Type;
   109          this.Deadline = a.Deadline;
   110          this.Cancelled = a.Cancelled;
   111          this.Fullfilled = a.Fullfilled;
   112      }
   113  }
   114  
   115  
   116  // See models/incident.go
   117  class IncidentState {
   118      Id: number;
   119      Start: string; // moment object?
   120      End: string; // Pointer so nullable, also moment?
   121      AlertKey: string;
   122      Alert: string;
   123  
   124      // Embedded properties of Result struct
   125      Value: number;
   126      Expr: string;
   127  
   128      Events: IncidentEvent[];
   129      Actions: Action[];
   130      Tags: string;
   131  
   132      Subject: string;
   133  
   134      NeedAck: boolean;
   135      Open: boolean;
   136      Unevaluated: boolean;
   137  
   138      CurrentStatus: string;
   139      WorstStatus: string;
   140  
   141      LastAbnormalStatus: string;
   142      LastAbnormalTime: number; // Epoch
   143  
   144      PreviousIds: number[];
   145      NextId: number;
   146  
   147      constructor(is) {
   148          this.Id = is.Id;
   149          this.Start = is.Start;
   150          this.End = is.End;
   151          this.AlertKey = is.AlertKey;
   152          this.Alert = is.Alert;
   153  
   154          this.Value = is.Value;
   155          this.Expr = is.Expr;
   156          this.Events = new Array<IncidentEvent>();
   157          if (is.Events) {
   158              for (let e of is.Events) {
   159                  this.Events.push(new IncidentEvent(e))
   160              }
   161          }
   162          this.Actions = new Array<Action>();
   163          this.Tags = is.Tags;
   164          if (is.Actions) {
   165              for (let a of is.Actions) {
   166                  this.Actions.push(new Action(a))
   167              }
   168          }
   169          this.Subject = is.Subject;
   170          this.NeedAck = is.NeedAck;
   171          this.Open = is.Open;
   172          this.Unevaluated = is.Unevaluated;
   173          this.CurrentStatus = is.CurrentStatus;
   174          this.WorstStatus = is.WorstStatus;
   175          this.LastAbnormalStatus = is.LastAbnormalStatus;
   176          this.LastAbnormalTime = is.LastAbnormalTime;
   177          this.PreviousIds = new Array<number>();
   178          if (is.PreviousIds) {
   179              for (let id of is.PreviousIds) {
   180                  this.PreviousIds.push(id);
   181              }
   182          }
   183          this.NextId = is.NextId;
   184      }
   185  
   186  
   187      IsPendingClose(): boolean {
   188          for (let action of this.Actions) {
   189              if (action.Deadline != undefined && !(action.Fullfilled || action.Cancelled)) {
   190                  return true;
   191              }
   192          }
   193          return false;
   194      }
   195  }
   196  
   197  class StateGroup {
   198      Active: boolean;
   199      Status: string;
   200      CurrentStatus: string;
   201      Silenced: boolean;
   202      IsError: boolean;
   203      Subject: string;
   204      Alert: string;
   205      AlertKey: string;
   206      Ago: string;
   207      State: IncidentState;
   208      Children: StateGroup[];
   209  
   210      constructor(sg) {
   211          this.Active = sg.Active;
   212          this.Status = sg.Status;
   213          this.CurrentStatus = sg.CurrentStatus;
   214          this.Silenced = sg.Silenced;
   215          this.IsError = sg.IsError;
   216          this.Subject = sg.Subject;
   217          this.Alert = sg.Alert;
   218          this.AlertKey = sg.AlertKey;
   219          this.Ago = sg.Ago;
   220          if (sg.State) {
   221              this.State = new IncidentState(sg.State);
   222          }
   223          this.Children = new Array<StateGroup>();
   224          if (sg.Children) {
   225              for (let c of sg.Children) {
   226                  this.Children.push(new StateGroup(c));
   227              }
   228          }
   229      }
   230  }
   231  
   232  class Groups {
   233      NeedAck: StateGroup[];
   234      Acknowledged: StateGroup[];
   235  
   236      constructor(g) {
   237          this.NeedAck = new Array<StateGroup>();
   238          if (g.NeedAck) {
   239              for (let sg of g.NeedAck) {
   240                  this.NeedAck.push(new StateGroup(sg));
   241              }
   242          }
   243          this.Acknowledged = new Array<StateGroup>();
   244          if (g.Acknowledged) {
   245              for (let sg of g.Acknowledged) {
   246                  this.Acknowledged.push(new StateGroup(sg));
   247              }
   248          }
   249      }
   250  }
   251  
   252  
   253  class StateGroups {
   254      Groups: Groups;
   255      TimeAndDate: number[];
   256      FailingAlerts: number;
   257      UnclosedErrors: number;
   258  
   259      constructor(sgs) {
   260          this.Groups = new Groups(sgs.Groups);
   261          this.TimeAndDate = sgs.TimeAndDate;
   262          this.FailingAlerts = sgs.FailingAlerts;
   263          this.UnclosedErrors = sgs.UnclosedErrors;
   264      }
   265  }