Skip to content

Commit

Permalink
replaces eval() with ast.literal_eval()
Browse files Browse the repository at this point in the history
  • Loading branch information
gurubert committed Oct 14, 2024
1 parent 9b9bc7d commit b5a2a75
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 18 deletions.
Binary file removed check_mk_api/check_mk_api-5.8.0.mkp
Binary file not shown.
Binary file added check_mk_api/check_mk_api-5.8.1.mkp
Binary file not shown.
12 changes: 4 additions & 8 deletions check_mk_api/lib/python3/checkmkapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
"""API-Wrapper for the CheckMK 2.0 REST API and the Multisite API (Views)"""

import requests
import warnings
import warnings # type: ignore
import os
import json
import time
import sys
import configparser
import json
from ast import literal_eval # type: ignore

def _check_mk_url(url):
""" adds trailing check_mk path component to URL """
Expand Down Expand Up @@ -81,8 +80,6 @@ def _check_response(self, resp):
else:
data = {}
etag = resp.headers.get('ETag', '').strip('"')
# if resp.status_code >= 400:
# sys.stderr.write("%r\n" % data)
return data, etag, resp

def _get_url(self, uri, etag=None, data={}):
Expand Down Expand Up @@ -1690,13 +1687,12 @@ def _api_request(self, api_url, params, data=None):
if resp.status_code == 200:
if "MESSAGE: " in resp.text:
msg = resp.text[resp.text.find("\n")+1:]
return eval(msg)
return literal_eval(msg)
if resp.text.startswith('ERROR: '):
raise ValueError(resp.text[7:])
else:
return eval(resp.text)
return literal_eval(resp.text)
else:
# sys.stderr.write("%s\n" % resp.text)
resp.raise_for_status()

def view(self, view_name, **kwargs):
Expand Down
10 changes: 5 additions & 5 deletions data2label/bin/data2label.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
# Robert Sander <[email protected]>
#

import argparse
import argparse # type: ignore
import checkmkapi
import re
import copy
from pprint import pprint
import re # type: ignore
from ast import literal_eval # type: ignore
from pprint import pprint # type: ignore

def get_host_labels(hostname):
host, etag = wato.get_host(hostname)
Expand All @@ -34,7 +34,7 @@ def get_host_labels(hostname):
parser.add_argument('-d', '--dump', action="store_true", help='Dump unique values from the view')
args = parser.parse_args()

conf = eval(open(args.config, 'r').read())
conf = literal_eval(open(args.config, 'r').read())
conf_labelmap = {}
for attr, patterns in conf['labelmap'].items():
conf_labelmap[attr] = {}
Expand Down
Binary file removed data2label/data2label-2.3.0.mkp
Binary file not shown.
Binary file added data2label/data2label-2.3.1.mkp
Binary file not shown.
10 changes: 5 additions & 5 deletions data2tag/bin/data2tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
# Robert Sander <[email protected]>
#

import argparse
import argparse # type: ignore
import checkmkapi
import re
import copy
from pprint import pprint
import re # type: ignore
from ast import literal_eval # type: ignore
from pprint import pprint # type: ignore

parser = argparse.ArgumentParser()
parser.add_argument('-s', '--url', help='URL to Check_MK site')
Expand All @@ -20,7 +20,7 @@
parser.add_argument('-d', '--dump', action="store_true", help='Dump unique values from the view')
args = parser.parse_args()

conf = eval(open(args.config, 'r').read())
conf = literal_eval(open(args.config, 'r').read())
conf_tagmap = {}
for attr, patterns in conf['tagmap'].items():
conf_tagmap[attr] = {}
Expand Down
Binary file removed data2tag/data2tag-1.4.1.mkp
Binary file not shown.
Binary file added data2tag/data2tag-1.4.2.mkp
Binary file not shown.

0 comments on commit b5a2a75

Please sign in to comment.