Nagios: Add support to communicate with servers with TLS
Added support to be able to talk to TLS enabled prometheus and elasticsearch by passing the CA cert to the request object. Change-Id: I0616b3e5d251cc6c9cd3cc28bc44977ff5164b3c
This commit is contained in:
parent
fc2a5cb320
commit
f6e73efa87
|
@ -24,6 +24,7 @@ import sys
|
|||
import argparse
|
||||
import datetime
|
||||
import json
|
||||
import os
|
||||
from pprint import pprint
|
||||
import requests
|
||||
|
||||
|
@ -223,13 +224,19 @@ def main():
|
|||
pprint(data)
|
||||
|
||||
try:
|
||||
kwargs = {
|
||||
'data': json.dumps(data),
|
||||
'timeout': args.timeout,
|
||||
'headers': {'Content-Type': 'application/json'}
|
||||
}
|
||||
if args.usr and args.pwd:
|
||||
response = requests.post(url, data=json.dumps(data), timeout=args.timeout,
|
||||
headers={"Content-Type": "application/json"},
|
||||
auth=(args.usr, args.pwd))
|
||||
else:
|
||||
response = requests.post(url, data=json.dumps(data), timeout=args.timeout,
|
||||
headers={"Content-Type": "application/json"})
|
||||
kwargs['auth'] = (args.usr, args.pwd)
|
||||
cacert = os.getenv('CA_CERT_PATH', "")
|
||||
if cacert:
|
||||
kwargs['verify'] = cacert
|
||||
|
||||
response = requests.post(url, **kwargs)
|
||||
|
||||
except requests.exceptions.Timeout as con_ex:
|
||||
NagiosUtil.service_warning('Elasticsearch connection timed out ' + str(con_ex))
|
||||
except requests.exceptions.RequestException as req_ex:
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
# Output:
|
||||
# CRITICAL: statefulset prometheus has low replica count
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
import requests
|
||||
import re
|
||||
|
@ -139,10 +140,15 @@ def query_prometheus(prometheus_api, alertname, labels_csv, timeout):
|
|||
promql = promql + "," + labels_csv
|
||||
promql = promql + "}"
|
||||
query = {'query': promql}
|
||||
response = requests.get(
|
||||
include_schema(prometheus_api) +
|
||||
"/api/v1/query",
|
||||
params=query, timeout=timeout)
|
||||
kwargs = {
|
||||
'params': query,
|
||||
'timeout': timeout
|
||||
}
|
||||
cacert = os.getenv('CA_CERT_PATH', "")
|
||||
if cacert:
|
||||
kwargs['verify'] = cacert
|
||||
|
||||
response = requests.get(include_schema(prometheus_api) + "/api/v1/query", **kwargs)
|
||||
response_json = response.json()
|
||||
except requests.exceptions.Timeout:
|
||||
error_messages.append(
|
||||
|
|
Loading…
Reference in New Issue