Skip to content

API Operator Log (Watches)

Matt Campbell edited this page Feb 4, 2015 · 1 revision

Operator Logs

Create new watch (if none are open)

curl -i --user admin:admin -XPOST http://localhost:4000/watch

Creates:

{
  "end_time": null,  
  "id": 3,  
  "start_time": "2015-01-23T19:20:02.907841",  
  "user": {  
  "email": "ooi@asascience.com",  
  "first_name": "Ad",  
 "last_name": "Min"  
 }  
}

Close watch

curl -i --user admin:admin -XPUT http://localhost:4000/watch/<watch_id>

Creates:

... end_time : Current date

Watches

{
  "end_time": null,
  "id": 1,
  "start_time": "2015-01-28T16:52:12.263956",
  "user": {
    "email": "ooi@asascience.com",
    "first_name": "Ad",
    "last_name": "Min"
  }
}

GET /watch

Returns the list of all Watches in the database or returns 204 if there are no watches in the system. The response is a list under the key watches.

{
  "watches": [
    {
      "end_time": null,
      "id": 1,
      "start_time": "2015-01-28T16:52:12.263956",
      "user": {
        "email": "ooi@asascience.com",
        "first_name": "Ad",
        "last_name": "Min"
      }
    }
  ]
}
Arguments

organization_id - Returns a list of watches that belong to an organization

Example:

GET /watches?organization_id=1

POST /watch

Requires Authentication

Creates a new Watch. The form data fields are completely ignored. A new post is created if and only if there is not already an open watch. Users can not and should not have two open watches at the same time.

{
  "end_time": null,
  "id": 1,
  "start_time": "2015-01-28T16:52:12.263956",
  "user": {
    "email": "ooi@asascience.com",
    "first_name": "Ad",
    "last_name": "Min"
  }
}
GET /watch/<int:watch_id>

Returns a record for a single watch given the watch_id

{
  "end_time": null,
  "id": 1,
  "start_time": "2015-01-28T16:52:12.263956",
  "user": {
    "email": "ooi@asascience.com",
    "first_name": "Ad",
    "last_name": "Min"
  }
}
PUT /watch/<int:watch_id>

Requires Authentication

Closes or updates a watch record. If the form data is empty it will close the latest watch created by the currently logged in user. The watch is closed by the services filling in the end_time attribute.

{
  "end_time": "2015-01-28T17:34:15.186735",
  "id": 1,
  "start_time": "2015-01-28T16:52:12.263956",
  "user": {
    "email": "ooi@asascience.com",
    "first_name": "Ad",
    "last_name": "Min"
  }
}
GET /watch/user

Requires Authentication

Returns the current set of watches that belong to the logged in user. The response is an array of records that are under the watches attribute for the root document.

GET /watch/open

Requires Authentication

Returns the last open watch for the currently logged in user or 204 if there is now open watch.

{
  "end_time": null,
  "id": 2,
  "start_time": "2015-01-28T17:45:32.327470",
  "user": {
    "email": "ooi@asascience.com",
    "first_name": "Ad",
    "last_name": "Min"
  }
}

Operator Events

GET /operator_event

Returns a list of all operator events in the system.

{
  "operator_events": [
    {
      "event_comment": "Shutdown the CTDBP on the inshore surface mooring.",
      "event_time": "2015-01-28T17:48:39.678702",
      "event_title": "Instrument Shutdown",
      "event_type": {
        "id": 1,
        "type_description": "General information event.",
        "type_name": "INFO"
      },
      "id": 1,
      "watch_id": 2
    }
  ]
}
Arguments

watch_id - Returns a list of operator events associated with a specific watch.

POST /operator_event

Requires Authentication

Creates a new operator event.

Necessary fields:

  • event_title
  • event_comment

Optional Fields:

  • event_type.type_name OR event_type.id
{
  "event_comment": "Shutdown the CTDBP on the inshore surface mooring.",
  "event_time": "2015-01-28T17:57:35.699145",
  "event_title": "Instrument Shutdown",
  "event_type": {
    "id": 1,
    "type_description": "General information event.",
    "type_name": "INFO"
  },
  "id": 2,
  "watch_id": 2
}

GET /operator_event/<int:operator_event_id>

Returns a specific operator event record with the given operator_event_id

{
  "event_comment": "Shutdown the CTDBP on the inshore surface mooring.",
  "event_time": "2015-01-28T17:57:35.699145",
  "event_title": "Instrument Shutdown",
  "event_type": {
    "id": 1,
    "type_description": "General information event.",
    "type_name": "INFO"
  },
  "id": 2,
  "watch_id": 2
}

PUT /operator_event/<int:operator_event_id>

Authentication Required

Updates a specific operator event record.

GET /operator_event_type

Returns a list of operator event types available in the system.

{
  "operator_event_types": [
    {
      "id": 1,
      "type_description": "General information event.",
      "type_name": "INFO"
    },
    {
      "id": 2,
      "type_description": "A warning has occurred.",
      "type_name": "WARN"
    },
    {
      "id": 3,
      "type_description": "An error has occurred.",
      "type_name": "ERROR"
    },
    {
      "id": 4,
      "type_description": "A critical event has occurred.",
      "type_name": "CRITICAL"
    },
    {
      "id": 5,
      "type_description": "Watch has started.",
      "type_name": "WATCH_START"
    },
    {
      "id": 6,
      "type_description": "Watch has ended.",
      "type_name": "WATCH_END"
    }
  ]
}

Scenario

  1. Create Empty Watch

    curl -i --user admin:admin -XPOST http://localhost:4000/watch
    
    HTTP/1.0 201 CREATED
    Content-Type: application/json
    Content-Length: 183
    Set-Cookie: session=eyJfaWQiOnsiIGIiOiJaakJtTlRsbE9HRTNObVpsWlRJd05qazBaakkwWXpnMFlqRTJOVGN3TTJZPSJ9fQ.B6q_wg.J84q9gGy-7T_1wrmFRuOYZLfTBM; HttpOnly; Path=/
    Server: Werkzeug/0.9.6 Python/2.7.6
    Date: Wed, 28 Jan 2015 18:45:22 GMT
    
    {
      "end_time": null,
      "id": 1,
      "start_time": "2015-01-28T18:45:22.186579",
      "user": {
        "email": "ooi@asascience.com",
        "first_name": "Ad",
        "last_name": "Min"
      }
    }
    
  2. Get the watch record

    curl -i -XGET http://localhost:4000/watch/1
    
    HTTP/1.0 200 OK
    Content-Type: application/json
    Content-Length: 183
    Set-Cookie: session=eyJfaWQiOnsiIGIiOiJaakJtTlRsbE9HRTNObVpsWlRJd05qazBaakkwWXpnMFlqRTJOVGN3TTJZPSJ9fQ.B6rAVw.MHAhfeFs6EWOCvBhlNj4pj_Ve0A; HttpOnly; Path=/
    Server: Werkzeug/0.9.6 Python/2.7.6
    Date: Wed, 28 Jan 2015 18:47:51 GMT
    
    {
      "end_time": null,
      "id": 1,
      "start_time": "2015-01-28T18:45:22.186579",
      "user": {
        "email": "ooi@asascience.com",
        "first_name": "Ad",
        "last_name": "Min"
      }
    }
    
  3. Close the watch

    curl -i --user admin:admin -XPUT http://localhost:4000/watch/1
    
    HTTP/1.0 201 CREATED
    Content-Type: application/json
    Content-Length: 207
    Set-Cookie: session=eyJfaWQiOnsiIGIiOiJaakJtTlRsbE9HRTNObVpsWlRJd05qazBaakkwWXpnMFlqRTJOVGN3TTJZPSJ9fQ.B6rAxw.3eUozGEPcNpQlzr66z_IcENGnuA; HttpOnly; Path=/
    Server: Werkzeug/0.9.6 Python/2.7.6
    Date: Wed, 28 Jan 2015 18:49:43 GMT
    
    {
      "end_time": "2015-01-28T18:49:43.243760", 
      "id": 1, 
      "start_time": "2015-01-28T18:45:22.186579", 
      "user": {
        "email": "ooi@asascience.com", 
        "first_name": "Ad", 
        "last_name": "Min"
      }
    }
    
  4. Open a new watch

    curl -i --user admin:admin -XPOST http://localhost:4000/watch
    
    HTTP/1.0 201 CREATED
    Content-Type: application/json
    Content-Length: 183
    Set-Cookie: session=eyJfaWQiOnsiIGIiOiJaakJtTlRsbE9HRTNObVpsWlRJd05qazBaakkwWXpnMFlqRTJOVGN3TTJZPSJ9fQ.B6rBFA.sjCwiFno5uLLOBrLHhqmb38ul3Q; HttpOnly; Path=/
    Server: Werkzeug/0.9.6 Python/2.7.6
    Date: Wed, 28 Jan 2015 18:51:00 GMT
    
    {
      "end_time": null, 
      "id": 2, 
      "start_time": "2015-01-28T18:51:00.568117", 
      "user": {
        "email": "ooi@asascience.com", 
        "first_name": "Ad", 
        "last_name": "Min"
      }
    }
    
  5. List the watches by the organization

    curl -i -XGET http://localhost:4000/watch?organization_id=1
    
    HTTP/1.0 200 OK
    Content-Type: application/json
    Content-Length: 496
    Set-Cookie: session=eyJfaWQiOnsiIGIiOiJaakJtTlRsbE9HRTNObVpsWlRJd05qazBaakkwWXpnMFlqRTJOVGN3TTJZPSJ9fQ.B6rBcw.WILJMu_RODl_8OBz17nn-J3btjQ; HttpOnly; Path=/
    Server: Werkzeug/0.9.6 Python/2.7.6
    Date: Wed, 28 Jan 2015 18:52:35 GMT
    
    {
      "watches": [
        {
          "end_time": "2015-01-28T18:49:43.243760", 
          "id": 1, 
          "start_time": "2015-01-28T18:45:22.186579", 
          "user": {
            "email": "ooi@asascience.com", 
            "first_name": "Ad", 
            "last_name": "Min"
          }
        }, 
        {
          "end_time": null, 
          "id": 2, 
          "start_time": "2015-01-28T18:51:00.568117", 
          "user": {
            "email": "ooi@asascience.com", 
            "first_name": "Ad", 
            "last_name": "Min"
          }
        }
      ]
    }
    
  6. Create a new operator event

    curl -i --user admin:admin -H 'Content-Type: application/json' -d '{"event_title":"Instrument Shutdown", "event_comment":"Shutdown the CTDBP on the inshore surface mooring.", "event_type":{"type_name":"INFO"}}' -XPOST http://localhost:4000/operator_event
    
    HTTP/1.0 201 CREATED
    Content-Type: application/json
    Content-Length: 310
    Set-Cookie: session=eyJfaWQiOnsiIGIiOiJaakJtTlRsbE9HRTNObVpsWlRJd05qazBaakkwWXpnMFlqRTJOVGN3TTJZPSJ9fQ.B6rCGw.y6b4J7XmVxSWA1MR-MUpWtcnfBQ; HttpOnly; Path=/
    Server: Werkzeug/0.9.6 Python/2.7.6
    Date: Wed, 28 Jan 2015 18:55:23 GMT
    
    {
      "event_comment": "Shutdown the CTDBP on the inshore surface mooring.", 
      "event_time": "2015-01-28T18:55:23.050320", 
      "event_title": "Instrument Shutdown", 
      "event_type": {
        "id": 1, 
        "type_description": "General information event.", 
        "type_name": "INFO"
      }, 
      "id": 1, 
      "watch_id": 2
    }
    
  7. See a list of operator events for the watch

    curl -i -XGET http://localhost:4000/operator_event?watch_id=2
    
    HTTP/1.0 200 OK
    Content-Type: application/json
    Content-Length: 389
    Set-Cookie: session=eyJfaWQiOnsiIGIiOiJaakJtTlRsbE9HRTNObVpsWlRJd05qazBaakkwWXpnMFlqRTJOVGN3TTJZPSJ9fQ.B6rCWg.M3EgL8aViBYh4LrM_br3JEe9484; HttpOnly; Path=/
    Server: Werkzeug/0.9.6 Python/2.7.6
    Date: Wed, 28 Jan 2015 18:56:26 GMT
    
    {
      "operator_events": [
        {
          "event_comment": "Shutdown the CTDBP on the inshore surface mooring.", 
          "event_time": "2015-01-28T18:55:23.050320", 
          "event_title": "Instrument Shutdown", 
          "event_type": {
            "id": 1, 
            "type_description": "General information event.", 
            "type_name": "INFO"
          }, 
          "id": 1, 
          "watch_id": 2
        }
      ]
    }