Best Practice Rules

With these methods, you can run best practice rules immediately, as well as view the historical results of running a specific best practice rule. Scheduling a best practice rule to run periodically can be done through the scheduling api: Schedule management

Managing Best Practice Rules  
Get historical results for running rules. GET /{cluster_id}/bestpractice/results
Get the latest results for all rules that have run. GET /{cluster_id}/bestpractice/results/latest
Run a best practice rule immediately. POST /{cluster_id}/bestpractice/run/{rule_name}

Managing Best Practice Rules

Best Practice Result

OpsCenter will return a json dictionary representing a single run of a best practice rule when querying for rule results.

A best practice result has the following form:

{
    "alert-level": ALERT_LEVEL,
    "category": CATEGORY,
    "description": DESCRIPTION,
    "display-name": DISPLAY,
    "enabled_by_default": ENABLED,
    "errors":
        {
            "cluster-error": CLUSTER_ERROR,
            "node-errors": NODE_ERRORS,
            "request-errors": REQUEST_ERRORS
        },
    "importance": IMPORTANCE,
    "name": NAME,
    "recommendation": RECOMMENDATION,
    "run_time": RUN_TIME,
    "scope": SCOPE,
    "status": STATUS,
    "suggested_interval": SUGGESTED_INTERVAL,
    "version": VERSION
}
Data:
  • ALERT_LEVEL (string) – The level used when creating an alert for the failed rule.
  • CATEGORY (string) – The category the rule is in. Used by the OpsCenter UI.
  • DESCRIPTION (string) – A detailed description of what the rule is checking
  • DISPLAY (string) – A UI friendly name for the rule.
  • ENABLED (string) – Whether the rule is enabled by default or not.
  • CLUSTER_ERROR (string) – If the rule failed, and is run at the cluster scope, this will be a description of the failure.
  • NODE_ERRORS (string) – The list of individual nodes that the rule failed to run on.
  • REQUEST_ERRORS (string) – The list of nodes that we were unable to run the rule on at all.
  • IMPORTANCE (string) – How important the rule passing is. Can be high, medium, or low.
  • RECOMMENDATION (string) – The suggested action to resolve the rule.
  • RUN_TIME (string) – The time this run of the rule occurred at
  • SCOPE (string) – The scope of the rule. Can be cluster, node, or cluster-and-node.
  • STATUS (string) – Either ‘Passed’ or ‘Failed’.
  • SUGGESTED_INTERVAL (string) – The recommended default interval for rules that are enabled by default.
  • VERSION (string) – The version of OpsCenter the rule was added in.
GET /{cluster_id}/bestpractice/results

Get the historical results of running the specified rules.

Path arguments:

cluster_id – The ID of a cluster returned from GET /cluster-configs.

Query params:

rules – A comma separated list of rules to fetch results for.

Opt. params:
  • start – A unix timestamp in seconds indicating the start of the window to retreive results for. Defaults to the current time.
  • end – A unix timestamp in seconds indicating the end of the window to retreive results for.
  • count – Number of results to return. Defaults to 100.

Returns a dictionary describing the rule results. Each key in the dictionary is the name of the rule and each value is an array of dictionaries describing the result.

Example

curl http://127.0.0.1:8888/Test_Cluster/bestpractice/results?count=1&rules=check-simple-strategy

Output:

{
    "check-simple-strategy": [
        {
            "alert-level": "alert",
            "category": "Replication",
            "description": "Checks that you are not using SimpleStrategy for any keyspaces in a multi-datacenter environment.",
            "display-name": "SimpleStrategy keyspace usage found",
            "enabled_by_default": true,
            "errors": {},
            "importance": "medium",
            "name": "check-simple-strategy",
            "recommendation": "Please update the replication strategies of the relevant keyspace(s) to use NetworkTopologyStrategy.",
            "run_time": "2014-07-22 23:37:14.329808",
            "scope": "cluster",
            "status": "Passed",
            "suggested_interval": "daily",
            "version": "5.0.0"
        }
    ]
}
GET /{cluster_id}/bestpractice/results/latest

Get the latest results for all rules that have run.

Path arguments:cluster_id – The ID of a cluster returned from GET /cluster-configs.

Returns a dictionary describing the rule results. Each key in the dictionary is the name of the rule and each value is a dictionary describing the latest run of the rule.

Example

curl http://127.0.0.1:8888/Test_Cluster/bestpractice/results/latest

Output:

{
    "check-simple-strategy": {
        "alert-level": "alert",
        "category": "Replication",
        "description": "Checks that you are not using SimpleStrategy for any keyspaces in a multi-datacenter environment.",
        "display-name": "SimpleStrategy keyspace usage found",
        "enabled_by_default": true,
        "errors": {},
        "importance": "medium",
        "name": "check-simple-strategy",
        "recommendation": "Please update the replication strategies of the relevant keyspace(s) to use NetworkTopologyStrategy.",
        "run_time": "2014-07-22 23:41:50.727939",
        "scope": "cluster",
        "status": "Passed",
        "suggested_interval": "daily",
        "version": "5.0.0"
    },
    "check-simple-snitch": {
        ...
    }
}
POST /{cluster_id}/bestpractice/run/{rule_name}

Run a specific best practice rule immediately.

Path arguments:
  • cluster_id – The ID of a cluster returned from GET /cluster-configs.
  • rule_name – The name of the rule to run.

Returns a dictionary describing the result of running the rule.

Example

curl -X POST http://127.0.0.1:8888/Test_Cluster/bestpractice/run/check-simple-strategy

Output:

{
    "alert-level": "alert",
    "category": "Replication",
    "description": "Checks that you are not using SimpleStrategy for any keyspaces in a multi-datacenter environment.",
    "display-name": "SimpleStrategy keyspace usage found",
    "enabled_by_default": true,
    "errors": {},
    "importance": "medium",
    "name": "check-simple-strategy",
    "recommendation": "Please update the replication strategies of the relevant keyspace(s) to use NetworkTopologyStrategy.",
    "run_time": "2014-07-22 23:44:22.179740",
    "scope": "cluster",
    "status": "Passed",
    "suggested_interval": "daily",
    "version": "5.0.0"
}