bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/annotate/web/README.md (about)

     1  Annotate takes annotations in a defined schema. The intent is to support multiple backends, but currently only works with elasticsearch. 
     2  
     3  The fields of an annotation and there suggested ussage are:
     4  
     5   * Id: This is a GUID. The GUID is set by the API, so you should only specify it when are changing an existing annotation
     6   * StartDate / EndDate: The start and end date of the annotation. When an annotation is an event without duration, StartDate equals the EndDate. The API can take times in either RFC3339 as referenced in [Go's time package](https://golang.org/pkg/time/) or a unix epoch. The two should not be mixed in the same annotation. 
     7   * CreationUser: Optional, The username of a human creating the annotation. For machine generated annotations, it is suggested to leave this field blank so the two can be distinguished.
     8   * Url: Optional, An optional link, like http://bosun.org
     9   * Source: Optional, The system that generated the annotation
    10   * Host: Optional,  hostname if the host. Recommended convention is all lowercase shortnames
    11   * Owner: Optional, The team or group that the annotation relates to
    12   * Message: Required, free form text 
    13  
    14  
    15  #REST End Points
    16  
    17  
    18  ## Create Annotation
    19  Annotations can be created using RFC3339 format or Epoch format (see examples below). The response will be in the same format as the annotation you created. This endpoint has the following behaviors:
    20   * If StartDate and EndDate are not set, the API endpoint will set the time to now
    21   * If StartDate or EndDate (and not both) is set, the endpoint will set the other to be the one that is set. So for single events, you need only specify one or the other
    22   * The Id is a GUID that is set my the API endpoint, and not the user. It gets returned in the response so you can updated the annotation in the future.
    23   * If an Id is set, then the annotation will be updated as long as the GUID exists. **Updates require the complete document, as all fields are overwritten (and if the field is missing, an empty value with overwrite what is there).** If the GUID is not found, an error will be returned.
    24  
    25  **URL**
    26  
    27  `/annotation`
    28  
    29  **Method and Request Type**
    30  
    31  `application/json`
    32  
    33  `POST` | `PUT`
    34   
    35  **URL Params**
    36  
    37  *None*
    38  
    39  **Data Params**
    40  
    41  *Example RFC3339 Format*
    42  
    43  ```
    44  {
    45    "Id": "",
    46    "Message": "test",
    47    "StartDate": "2016-02-24T22:08:41-05:00",
    48    "EndDate": "2016-02-24T22:08:41-05:00",
    49    "CreationUser": "kbrandt",
    50    "Url": "",
    51    "Source": "annotate-ui",
    52    "Host": "",
    53    "Owner": "sre",
    54    "Category": "test"
    55  }
    56  ```
    57  
    58  *Example Epoch Format*
    59  
    60  ```
    61  {
    62    "Id": "",
    63    "Message": "test",
    64    "StartDate": 1456369836,
    65    "EndDate": 1456369836,
    66    "CreationUser": "kbrandt",
    67    "Url": "",
    68    "Source": "annotate-ui",
    69    "Host": "",
    70    "Owner": "sre",
    71    "Category": "test"
    72  }
    73  ```
    74  
    75  **Response**
    76  
    77  Success:
    78  
    79  Code: 200
    80  
    81  *Example Epoch format*
    82  
    83  ```
    84  {
    85    "Id": "78a59f94-76ed-42d2-9ed0-9c7b282c4e83",
    86    "Message": "test",
    87    "CreationUser": "kbrandt",
    88    "Url": "",
    89    "Source": "annotate-ui",
    90    "Host": "",
    91    "Owner": "sre",
    92    "Category": "test",
    93    "StartDate": 1456369836,
    94    "EndDate": 1456369836
    95  }
    96  ```
    97  
    98  Failure
    99  
   100  Code: 500
   101  
   102  *Example*
   103    
   104  ```
   105  {
   106      "error": "EndDate is before StartDate"}
   107  }
   108  ```
   109  ***
   110  
   111  ## Get Annotation
   112  
   113  **URL**
   114  
   115  `/annotation/:id?Epoch=1`
   116  
   117  * `id` is the GUID of the annotation
   118  * Example: `annotation/78a59f94-76ed-42d2-9ed0-9c7b282c4e83?Epoch=1`
   119  
   120  **Method and Request Type**
   121  
   122  `application/json`
   123  
   124  `GET`
   125   
   126  **URL Params**
   127  
   128  *Optional*
   129   * `Epoch=1` makes it so the response has time as Epoch numbers instead of RFC3339 time.
   130  
   131  **Response**
   132  
   133  Success:
   134  
   135  Code: 200
   136  
   137  *Example Epoch format*
   138  
   139  ```
   140  {
   141    "Id": "78a59f94-76ed-42d2-9ed0-9c7b282c4e83",
   142    "Message": "test",
   143    "CreationUser": "kbrandt",
   144    "Url": "",
   145    "Source": "annotate-ui",
   146    "Host": "",
   147    "Owner": "sre",
   148    "Category": "test",
   149    "StartDate": 1456369836,
   150    "EndDate": 1456369836
   151  }
   152  ```
   153  
   154  Failure:
   155  
   156  Code: 500
   157  
   158  *Example*
   159    
   160  ```
   161  {
   162      "error":"elastic: Error 404 (Not Found)"
   163  }
   164  ```
   165  
   166  ***
   167  
   168  
   169  
   170  ## Update Annotation
   171  This has the same behavior as Create Annotation, but lets you put the id in the url. Whenever updating an annotation, the full annotation gets overwritten. So if you leave a field out, it will be zero'd out. 
   172  
   173  **URL**
   174  
   175  `/annotation/:id`
   176  
   177  **Method and Request Type**
   178  
   179  `application/json`
   180  
   181  `PUT`
   182   
   183  ***
   184  
   185  
   186  ## Get Field Values
   187  Get existing unique values for on any of the following fields:
   188   * `Source`
   189   * `Host`
   190   * `Category`
   191   * `CreationUser`
   192  
   193  
   194  **URL**
   195  
   196  `/annotation/values/:field`
   197   * field must be one of the above fields
   198   * example: `/annotation/values/Category`
   199  
   200  **Method and Request Type**
   201  
   202  `application/json`
   203  
   204  `GET`
   205  
   206  **Response**
   207  
   208  Success:
   209  
   210  Code: 200
   211  
   212  *Example*
   213  
   214  ```
   215  [
   216    "test",
   217    "outage"
   218  ]
   219  ```
   220  
   221  Failure
   222  
   223  Code: 500
   224  
   225  *Example*
   226    
   227  ```
   228  {
   229      "error":"invalid field Sizource"
   230  }
   231  ```
   232  
   233  ***
   234  
   235  ## Query Annotations
   236  Partially Documented - still highly subject to change. But if you provide a StartDate and EndDate, you will get the annotations that were active during the specified window. 
   237  
   238  **URL**
   239  
   240  `/annotation/query`
   241  
   242   * Example: `annotation/query?StartDate=2016-02-23T10:09:13-05:00&EndDate=2016-02-26T10:09:13-05:00`
   243   
   244  **Method and Request Type**
   245  
   246  `application/json`
   247  
   248  `GET`
   249  
   250  **Response**
   251  
   252  Success:
   253  
   254  Code 200
   255  
   256  *Example*
   257  
   258  ```
   259  [
   260    {
   261      "Id": "2c5ec8f9-3a3e-4d2e-a236-6aa42ef1077b",
   262      "Message": "test",
   263      "CreationUser": "kbrandt",
   264      "Url": "",
   265      "Source": "annotate-ui",
   266      "Host": "",
   267      "Owner": "sre",
   268      "Category": "outage",
   269      "StartDate": "2016-02-24T22:10:36-05:00",
   270      "EndDate": "2016-02-24T22:10:36-05:00"
   271    },
   272    {
   273      "Id": "af83d59b-a6bb-46a6-8d16-ba0e903eab0a",
   274      "Message": "test",
   275      "CreationUser": "kbrandt",
   276      "Url": "",
   277      "Source": "annotate-ui",
   278      "Host": "",
   279      "Owner": "sre",
   280      "Category": "test",
   281      "StartDate": "2016-02-24T22:10:36-05:00",
   282      "EndDate": "2016-02-24T22:10:36-05:00"
   283    }
   284  ]
   285  ```
   286  
   287  Error:
   288  
   289  Code 500
   290  
   291  *Example*
   292  
   293  ```
   294  {
   295    "error": "couldn't parse EndDate as RFC3339 or epoch: parsing time \"2016-02-a26T10:09:13-05:00\" as \"2006-01-02T15:04:05Z07:00\": cannot parse \"a26T10:09:13-05:00\" as \"02\", strconv.ParseInt: parsing \"2016-02-23T10:09:13-05:00\": invalid syntax"
   296  }
   297  ```