diff --git a/check_graylog.py b/check_graylog.py index 2415fa0..73b28bd 100755 --- a/check_graylog.py +++ b/check_graylog.py @@ -168,9 +168,9 @@ def main(): input_traffic_avg = sum([v for k, v in traffic_last_24_hrs['input'].items() if parse_traffic_ts(k)]) output_traffic_avg = sum([v for k, v in traffic_last_24_hrs['output'].items() if parse_traffic_ts(k)]) - elastisearch_health = fetch_with_retry(f'{base_url}/api/system/indexer/cluster/health', headers=headers, auth=(args.token, 'token'), verify=args.insecure).json() - elastisearch_status = elastisearch_health['status'].lower() - elastisearch_active_shards = elastisearch_health['shards']['active'] + elasticsearch_health = fetch_with_retry(f'{base_url}/api/system/indexer/cluster/health', headers=headers, auth=(args.token, 'token'), verify=args.insecure).json() + elasticsearch_status = elasticsearch_health['status'].lower() + elasticsearch_active_shards = elasticsearch_health['shards']['active'] indexer_failures = fetch_with_retry(f'{base_url}/api/system/indexer/failures?limit=10&offset=0', headers=headers, auth=(args.token, 'token'), verify=args.insecure).json() @@ -205,8 +205,8 @@ def main(): 'min': 0, 'unit': 'B', }, - 'elastisearch_active_shards': { - 'value': elastisearch_active_shards, + 'elasticsearch_active_shards': { + 'value': elasticsearch_active_shards, 'min': 0 }, 'indexer_failures': { @@ -235,23 +235,23 @@ def main(): indexer_failures_exit = nagios.STATE_OK # https://go2docs.graylog.org/5-0/setting_up_graylog/elasticsearch.htm#ClusterStatusExplained - if elastisearch_status == 'yellow': - elastisearch_exit_code = nagios.STATE_WARN + if elasticsearch_status == 'yellow': + elasticsearch_exit_code = nagios.STATE_WARN text_result += ' Elasticsearch is condition YELLOW!' - elif elastisearch_status == 'red': - elastisearch_exit_code = nagios.STATE_CRIT + elif elasticsearch_status == 'red': + elasticsearch_exit_code = nagios.STATE_CRIT text_result += ' Elasticsearch is condition RED!' - elif elastisearch_status == 'green': - elastisearch_exit_code = nagios.STATE_OK + elif elasticsearch_status == 'green': + elasticsearch_exit_code = nagios.STATE_OK else: - print_icinga2_check_status(f'unknown Elasticsearch health: {elastisearch_status}', nagios.STATE_UNKNOWN) + print_icinga2_check_status(f'unknown Elasticsearch health: {elasticsearch_status}', nagios.STATE_UNKNOWN) sys.exit(nagios.STATE_UNKNOWN) jvm_mem_usage_state = get_state(int(metrics_data['jvm_memory_heap_used']), jvm_mem_usage_warn, jvm_mem_usage_crit, operator='gt') if jvm_mem_usage_state != nagios.STATE_OK: text_result += f' JVM memory usage is high!' - exit_code = max(nagios.STATE_OK, jvm_mem_usage_state, elastisearch_exit_code, indexer_failures_exit) + exit_code = max(nagios.STATE_OK, jvm_mem_usage_state, elasticsearch_exit_code, indexer_failures_exit) if notifications['total'] > 0: text_result += f' There are notifications!' @@ -263,7 +263,7 @@ def main(): text_result = text_result + f' JVM memory usage: {int((perfdata["jvm_memory_used"]["value"] / metrics_data["jvm_memory_heap_max"]) * 100)}%' else: # show more data - text_result = text_result + f' JVM memory usage: {int((perfdata["jvm_memory_used"]["value"] / metrics_data["jvm_memory_heap_max"]) * 100)}%, throughput last 1 second: {human_readable_size(perfdata["throughput_input_1_sec_rate"]["value"])} in - {human_readable_size(perfdata["throughput_output_1_sec_rate"]["value"])} out, Elastisearch active shards: {perfdata["elastisearch_active_shards"]["value"]}' + text_result = text_result + f' JVM memory usage: {int((perfdata["jvm_memory_used"]["value"] / metrics_data["jvm_memory_heap_max"]) * 100)}%, throughput last 1 second: {human_readable_size(perfdata["throughput_input_1_sec_rate"]["value"])} in - {human_readable_size(perfdata["throughput_output_1_sec_rate"]["value"])} out, Elasticsearch active shards: {perfdata["elasticsearch_active_shards"]["value"]}' if args.input: text_result = text_result + f' {input_name_clean} events/second for last minute: {perfdata[f"{input_name_clean}_incoming_messages_rate_per_sec_1min"]["value"]}, {input_name_clean}_connections: {perfdata[f"{input_name_clean}_connections"]["value"]}, {input_name_clean}_network_in_total: {human_readable_size(perfdata[f"{input_name_clean}_network_in_total"]["value"], decimal_places=0)}'