Cluster roles API

The /clusterroles API endpoint

/clusterroles (GET)

The /clusterroles API endpoint provides HTTP GET access to cluster role data.

EXAMPLE

The following example demonstrates a request to the /clusterroles API endpoint, resulting in a JSON array that contains cluster role definitions.

curl -X GET \
http://127.0.0.1:8080/api/core/v2/clusterroles \
-H "Authorization: Bearer $SENSU_ACCESS_TOKEN"

HTTP/1.1 200 OK
[
  {
    "rules": [
      {
        "verbs": [
          "*"
        ],
        "resources": [
          "assets",
          "checks",
          "entities",
          "extensions",
          "events",
          "filters",
          "handlers",
          "hooks",
          "mutators",
          "silenced",
          "roles",
          "rolebindings"
        ],
        "resource_names": null
      },
      {
        "verbs": [
          "get",
          "list"
        ],
        "resources": [
          "namespaces"
        ],
        "resource_names": null
      }
    ],
    "metadata": {
      "name": "admin"
    }
  },
  {
    "rules": [
      {
        "verbs": [
          "*"
        ],
        "resources": [
          "*"
        ],
        "resource_names": null
      }
    ],
    "metadata": {
      "name": "cluster-admin",
      "created_by": "admin"
    }
  }
]

API Specification

/clusterroles (GET)
description Returns the list of cluster roles.
example url http://hostname:8080/api/core/v2/clusterroles
pagination This endpoint supports pagination using the limit and continue query parameters.
response filtering This endpoint supports API response filtering.
response type Array
response codes
  • Success: 200 (OK)
  • Error: 500 (Internal Server Error)
output
[
  {
    "rules": [
      {
        "verbs": [
          "*"
        ],
        "resources": [
          "*"
        ],
        "resource_names": null
      }
    ],
    "metadata": {
      "name": "cluster-admin",
      "created_by": "admin"
    }
  }
]

/clusterroles (POST)

The /clusterroles API endpoint provides HTTP POST access to create a cluster role.

EXAMPLE

In the following example, an HTTP POST request is submitted to the /clusterroles API endpoint to create a global-event-reader cluster role. The request includes the cluster role definition in the request body and returns a successful HTTP 201 Created response.

curl -X POST \
-H "Authorization: Bearer $SENSU_ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-d '{
  "metadata": {
    "name": "global-event-reader"
  },
  "rules": [
    {
      "verbs": [
        "get",
        "list"
      ],
      "resources": [
        "events"
      ],
      "resource_names": null
    }
  ]
}' \
http://127.0.0.1:8080/api/core/v2/clusterroles

HTTP/1.1 201 Created

API Specification

/clusterroles (POST)
description Creates a Sensu cluster role.
example URL http://hostname:8080/api/core/v2/clusterroles
payload
{
  "metadata": {
    "name": "global-event-reader"
  },
  "rules": [
    {
      "verbs": [
        "get",
        "list"
      ],
      "resources": [
        "events"
      ],
      "resource_names": null
    }
  ]
}
response codes
  • Success: 201 (Created)
  • Malformed: 400 (Bad Request)
  • Error: 500 (Internal Server Error)

The /clusterroles/:clusterrole API endpoint

/clusterroles/:clusterrole (GET)

The /clusterroles/:clusterrole API endpoint provides HTTP GET access to cluster role data for specific :clusterrole definitions, by cluster role name.

EXAMPLE

In the following example, querying the /clusterroles/:clusterrole API endpoint returns a JSON map that contains the requested :clusterrole definition (in this example, for the :clusterrole named global-event-reader).

curl -X GET \
http://127.0.0.1:8080/api/core/v2/clusterroles/global-event-reader \
-H "Authorization: Bearer $SENSU_ACCESS_TOKEN"

HTTP/1.1 200 OK
{
  "metadata": {
    "name": "global-event-reader",
    "created_by": "admin"
  },
  "rules": [
    {
      "verbs": [
        "get",
        "list"
      ],
      "resources": [
        "events"
      ],
      "resource_names": null
    }
  ]
}

API Specification

/clusterroles/:clusterrole (GET)
description Returns the specified cluster role.
example url http://hostname:8080/api/core/v2/clusterroles/global-event-reader
response type Map
response codes
  • Success: 200 (OK)
  • Missing: 404 (Not Found)
  • Error: 500 (Internal Server Error)
output
{
  "metadata": {
    "name": "global-event-reader",
    "created_by": "admin"
  },
  "rules": [
    {
      "verbs": [
        "get",
        "list"
      ],
      "resources": [
        "events"
      ],
      "resource_names": null
    }
  ]
}

/clusterroles/:clusterrole (PUT)

The /clusterroles/:clusterrole API endpoint provides HTTP PUT access to create or update a cluster role, by cluster role name.

EXAMPLE

In the following example, an HTTP PUT request is submitted to the /clusterroles/:clusterrole API endpoint to update the global-event-reader cluster role by adding "checks" to the resources. The request includes the cluster role definition in the request body and returns a successful HTTP 201 Created response.

curl -X PUT \
-H "Authorization: Bearer $SENSU_ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-d '{
  "metadata": {
    "name": "global-event-reader"
  },
  "rules": [
    {
      "verbs": [
        "get",
        "list"
      ],
      "resources": [
        "checks",
        "events"
      ],
      "resource_names": null
    }
  ]
}' \
http://127.0.0.1:8080/api/core/v2/clusterroles

HTTP/1.1 201 Created

API Specification

/clusterroles/:clusterrole (PUT)
description Creates or updates the specified Sensu cluster role.
example URL http://hostname:8080/api/core/v2/clusterroles/global-event-reader
payload
{
  "metadata": {
    "name": "global-event-reader"
  },
  "rules": [
    {
      "verbs": [
        "get",
        "list"
      ],
      "resources": [
        "events"
      ],
      "resource_names": null
    }
  ]
}
response codes
  • Success: 201 (Created)
  • Malformed: 400 (Bad Request)
  • Error: 500 (Internal Server Error)

/clusterroles/:clusterrole (DELETE)

The /clusterroles/:clusterrole API endpoint provides HTTP DELETE access to delete a cluster role from Sensu (specified by the cluster role name).

EXAMPLE

The following example shows a request to the /clusterroles/:clusterrole API endpoint to delete the cluster role global-event-reader, resulting in a successful HTTP 204 No Content response.

curl -X DELETE \
-H "Authorization: Bearer $SENSU_ACCESS_TOKEN" \
http://127.0.0.1:8080/api/core/v2/clusterroles/global-event-reader

HTTP/1.1 204 No Content

API Specification

/clusterroles/:clusterrole (DELETE)
description Removes a cluster role from Sensu (specified by the cluster role name).
example url http://hostname:8080/api/core/v2/clusterroles/global-event-reader
response codes
  • Success: 204 (No Content)
  • Missing: 404 (Not Found)
  • Error: 500 (Internal Server Error)