Skip to content

Instantly share code, notes, and snippets.

@CesarCapillas
Last active July 27, 2023 06:33
Show Gist options
  • Select an option

  • Save CesarCapillas/d31e7b446dc982f329d2c6a47e2b5ea1 to your computer and use it in GitHub Desktop.

Select an option

Save CesarCapillas/d31e7b446dc982f329d2c6a47e2b5ea1 to your computer and use it in GitHub Desktop.

Revisions

  1. CesarCapillas revised this gist Apr 23, 2018. 1 changed file with 68 additions and 0 deletions.
    68 changes: 68 additions & 0 deletions check-kibana.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,68 @@
    #!/bin/bash

    SERVER=${1:-localhost}
    PORT=${2:-5601}
    VAR=${3:-status}
    WARNING=${4:-1}
    CRITICAL=${5:-2}

    if [ "$PORT" = "443" ]; then
    PROTOCOL="https"
    else
    PROTOCOL="http"
    fi

    # Endpoint for Kibana API status
    ENDPOINT="$PROTOCOL://${SERVER}:${PORT}/api/status"

    if [[ "$1" == "" ]]; then
    echo "USAGE:"
    echo " check_kibana.sh <SERVER> <PORT> <VAR=status|load|heap> <WARNING> <CRITICAL>"
    exit
    fi

    CURL=`curl --silent -X GET ${ENDPOINT}`
    CHCK=`echo $CURL | grep "$VAR"`

    if [[ "$CHCK" == "" ]]; then
    CHECK="Failed"
    else
    CHECK="OK"
    fi

    if [[ "$CHECK" == "OK" ]]; then
    if [[ "$VAR" == "status" ]]; then
    MYDIV=`echo $CURL | jq ".status.overall.state"`
    if [[ "$MYDIV" == "\"green\"" ]]; then
    echo "INFO: Kibana ($VAR) = $MYDIV"
    exit 0
    else
    echo "WARN: Kibana ($VAR) = $MYDIV"
    exit 1
    fi
    fi
    if [[ "$VAR" == "load" ]]; then
    # Kibana 6
    MYDIV=`echo $CURL | jq ".metrics.os.cpu.load_average" | tr '\n' ' ' | sed -e 's/ / /g'`
    # Kibana 5
    #MYDIV=`echo $CURL | jshon -e "metrics" | jshon -e "load" | jshon -e 0 | jshon -e 1 | tr '\n' ' '`
    echo "INFO: Kibana ($VAR) = $MYDIV"
    exit 0
    fi
    if [[ "$VAR" == "heap" ]]; then
    # Kibana 6
    MYDIV=`echo $CURL | jq ".metrics.process.mem" | tr '\n' ' ' | sed -e 's/ / /g'`
    echo "INFO: Kibana ($VAR) = $MYDIV"
    exit 0
    fi
    # Kibana 5
    #MYDIV=`echo $CURL | jshon -e "metrics" | jshon -e "$VAR" | jshon -e 0 | jshon -e 1`
    #echo "INFO: Kibana ($VAR) = $MYDIV"
    #exit 0
    elif [[ "$CHECK" == "Failed" ]]; then
    echo "CRITICAL: ${SERVER}"
    exit 2
    else
    echo "Check failed."
    exit 3
    fi
  2. CesarCapillas created this gist Mar 18, 2018.
    11 changes: 11 additions & 0 deletions check-elastic-health.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    #!/bin/bash

    ELKSERVER=${1:-localhost}
    ELKPORT=${2:-9200}
    if [ -z "$ELKSERVER" ]; then
    # Usage
    echo 'Usage: check-health.sh <elk-server=localhost> <elk-port=9200>'
    # create-index.sh "logstash-solr-*"
    else
    curl -s "http://$ELKSERVER:$ELKPORT/_cat/health?v"
    fi
    14 changes: 14 additions & 0 deletions check-kibana-status.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    #!/bin/bash
    KIBANAMODE=${1:-"-b"}
    KIBANASERVER=${2:-localhost}
    KIBANAPORT=${3:-5601}
    if [ -z "$KIBANASERVER" ]; then
    # Usage
    echo 'Usage: check-kibana-status.sh <-b|-f> [<kibana-server=localhost> <kibana-port=5601>]'
    else
    if [ "$KIBANAMODE" = "-b" ]; then
    curl -s "http://$KIBANASERVER:$KIBANAPORT/api/status" | jq ".status.overall"
    else
    curl -s "http://$KIBANASERVER:$KIBANAPORT/api/status" | jq ".status.statuses"
    fi
    fi
    15 changes: 15 additions & 0 deletions create-index-pattern.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    #!/bin/bash
    KIBANASERVER=${2:-localhost}
    KIBANAPORT=${3:-5601}
    if [ -z "$1" ]; then
    # Usage
    echo 'Usage: create-index-pattern.sh <index-name="logstash-*">'
    # create-index.sh "logstash-solr-*"
    else
    echo "Creating index pattern $1 in Kibana"

    curl -XPOST -D- "http://$KIBANASERVER:$KIBANAPORT/api/saved_objects/index-pattern" \
    -H 'Content-Type: application/json' \
    -H 'kbn-version: 6.1.0' \
    -d "{\"attributes\":{\"title\":\"$1\",\"timeFieldName\":\"@timestamp\"}}"
    fi
    11 changes: 11 additions & 0 deletions delete-index.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    #!/bin/bash
    ELKSERVER=${2:-localhost}
    ELKPORT=${3:-9200}

    if [ -z "$1" ]; then
    # Usage
    echo 'Usage: delete-index.sh <index-name="logstash-2017.10.23">'
    else
    echo "Deleting index pattern $1 in Elastic Search"
    curl -s -XDELETE "http://$ELKSERVER:$ELKPORT/$1"
    fi
    17 changes: 17 additions & 0 deletions do-el-search.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    #!/bin/bash
    QUERY=${1:-*:*}
    ELKINDEX=${2:-_all}
    ROWS=${3:-10}
    FL=${4:-host,message,@timestamp}
    ELKSERVER=${5:-localhost}
    ELKPORT=${6:-9200}

    if [ -z "$1" ]; then
    # Usage
    echo 'Usage: do-search.sh <q=*:*> <index-name="logstash-2017.10.23"> <rows=10> <fl=host,message,@timestamp>'
    else
    COMMAND=`curl -s "http://$ELKSERVER:$ELKPORT/$ELKINDEX/_search?q=$QUERY&size=$ROWS&_source=$FL&pretty=true"`
    echo $COMMAND | jq
    echo "Number of results for search: $QUERY"
    echo $COMMAND | jq ".hits.total"
    fi
    10 changes: 10 additions & 0 deletions get-mapping.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    #!/bin/bash
    ELKSERVER=${2:-localhost}
    ELKPORT=${3:-9200}

    if [ -z "$1" ]; then
    # Usage
    echo 'Usage: get-mapping.sh <index-name="logstash-2017.10.23">'
    else
    curl -s http://$ELKSERVER:$ELKPORT/$1/_mapping | jq ".\"$1\".mappings.doc.properties"| jshon -k
    fi
    16 changes: 16 additions & 0 deletions list-indices.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    #!/bin/bash

    ELKMODE=${1:-"-f"}
    ELKSERVER=${2:-localhost}
    ELKPORT=${3:-9200}
    if [ -z "$ELKMODE" ]; then
    # Usage
    echo 'Usage: list-indices.sh <-b|-f> [<elk-server=localhost> <elk-port=9200>]'
    # create-index.sh "logstash-solr-*"
    else
    if [ "$ELKMODE" = "-b" ]; then
    curl -s "http://$ELKSERVER:$ELKPORT/_cat/indices?v" | awk '{print $3}' | grep -v "index" | sort
    else
    curl -s "http://$ELKSERVER:$ELKPORT/_cat/indices?v"
    fi
    fi