besapi 3.3.3__tar.gz → 3.4.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {besapi-3.3.3/src/besapi.egg-info → besapi-3.4.2}/PKG-INFO +1 -1
- {besapi-3.3.3 → besapi-3.4.2}/src/besapi/besapi.py +1 -1
- {besapi-3.3.3 → besapi-3.4.2}/src/besapi/plugin_utilities.py +41 -18
- {besapi-3.3.3 → besapi-3.4.2/src/besapi.egg-info}/PKG-INFO +1 -1
- {besapi-3.3.3 → besapi-3.4.2}/LICENSE.txt +0 -0
- {besapi-3.3.3 → besapi-3.4.2}/MANIFEST.in +0 -0
- {besapi-3.3.3 → besapi-3.4.2}/README.md +0 -0
- {besapi-3.3.3 → besapi-3.4.2}/pyproject.toml +0 -0
- {besapi-3.3.3 → besapi-3.4.2}/setup.cfg +0 -0
- {besapi-3.3.3 → besapi-3.4.2}/setup.py +0 -0
- {besapi-3.3.3 → besapi-3.4.2}/src/besapi/__init__.py +0 -0
- {besapi-3.3.3 → besapi-3.4.2}/src/besapi/__main__.py +0 -0
- {besapi-3.3.3 → besapi-3.4.2}/src/besapi/schemas/BES.xsd +0 -0
- {besapi-3.3.3 → besapi-3.4.2}/src/besapi/schemas/BESAPI.xsd +0 -0
- {besapi-3.3.3 → besapi-3.4.2}/src/besapi/schemas/BESActionSettings.xsd +0 -0
- {besapi-3.3.3 → besapi-3.4.2}/src/besapi.egg-info/SOURCES.txt +0 -0
- {besapi-3.3.3 → besapi-3.4.2}/src/besapi.egg-info/dependency_links.txt +0 -0
- {besapi-3.3.3 → besapi-3.4.2}/src/besapi.egg-info/requires.txt +0 -0
- {besapi-3.3.3 → besapi-3.4.2}/src/besapi.egg-info/top_level.txt +0 -0
- {besapi-3.3.3 → besapi-3.4.2}/src/bescli/__init__.py +0 -0
- {besapi-3.3.3 → besapi-3.4.2}/src/bescli/__main__.py +0 -0
- {besapi-3.3.3 → besapi-3.4.2}/src/bescli/bescli.py +0 -0
- {besapi-3.3.3 → besapi-3.4.2}/tests/tests.py +0 -0
|
@@ -11,6 +11,7 @@ import sys
|
|
|
11
11
|
import besapi
|
|
12
12
|
|
|
13
13
|
|
|
14
|
+
# NOTE: This does not work as expected when run from plugin_utilities
|
|
14
15
|
def get_invoke_folder(verbose=0):
|
|
15
16
|
"""Get the folder the script was invoked from"""
|
|
16
17
|
# using logging here won't actually log it to the file:
|
|
@@ -30,6 +31,7 @@ def get_invoke_folder(verbose=0):
|
|
|
30
31
|
return invoke_folder
|
|
31
32
|
|
|
32
33
|
|
|
34
|
+
# NOTE: This does not work as expected when run from plugin_utilities
|
|
33
35
|
def get_invoke_file_name(verbose=0):
|
|
34
36
|
"""Get the filename the script was invoked from"""
|
|
35
37
|
# using logging here won't actually log it to the file:
|
|
@@ -86,41 +88,41 @@ def setup_plugin_argparse(plugin_args_required=False):
|
|
|
86
88
|
return arg_parser
|
|
87
89
|
|
|
88
90
|
|
|
89
|
-
def setup_plugin_logging(
|
|
91
|
+
def setup_plugin_logging(log_file_path="", verbose=0, console=True):
|
|
90
92
|
"""setup logging for plugin use"""
|
|
91
|
-
# get folder the script was invoked from:
|
|
92
|
-
invoke_folder = get_invoke_folder(verbose)
|
|
93
93
|
|
|
94
|
-
if not
|
|
95
|
-
|
|
94
|
+
if not log_file_path or log_file_path == "":
|
|
95
|
+
log_file_path = os.path.join(
|
|
96
|
+
get_invoke_folder(verbose), get_invoke_file_name(verbose) + ".log"
|
|
97
|
+
)
|
|
96
98
|
|
|
97
99
|
# set different log levels:
|
|
98
100
|
log_level = logging.WARNING
|
|
99
101
|
if verbose:
|
|
100
102
|
log_level = logging.INFO
|
|
103
|
+
print("INFO: Log File Path:", log_file_path)
|
|
101
104
|
if verbose > 1:
|
|
102
105
|
log_level = logging.DEBUG
|
|
103
106
|
|
|
104
|
-
# get path to put log file in:
|
|
105
|
-
log_filename = os.path.join(invoke_folder, log_file_name)
|
|
106
|
-
|
|
107
107
|
handlers = [
|
|
108
108
|
logging.handlers.RotatingFileHandler(
|
|
109
|
-
|
|
109
|
+
log_file_path, maxBytes=5 * 1024 * 1024, backupCount=1
|
|
110
110
|
)
|
|
111
111
|
]
|
|
112
112
|
|
|
113
113
|
# log output to console if arg provided:
|
|
114
114
|
if console:
|
|
115
115
|
handlers.append(logging.StreamHandler())
|
|
116
|
+
print("INFO: also logging to console")
|
|
116
117
|
|
|
117
|
-
#
|
|
118
|
-
|
|
119
|
-
encoding
|
|
120
|
-
level
|
|
121
|
-
format
|
|
122
|
-
handlers
|
|
123
|
-
|
|
118
|
+
# return logging config:
|
|
119
|
+
return {
|
|
120
|
+
"encoding": "utf-8",
|
|
121
|
+
"level": log_level,
|
|
122
|
+
"format": "%(asctime)s %(levelname)s:%(message)s",
|
|
123
|
+
"handlers": handlers,
|
|
124
|
+
"force": True,
|
|
125
|
+
}
|
|
124
126
|
|
|
125
127
|
|
|
126
128
|
def get_besapi_connection(args):
|
|
@@ -134,6 +136,9 @@ def get_besapi_connection(args):
|
|
|
134
136
|
print("Password was not provided, provide REST API password:")
|
|
135
137
|
password = getpass.getpass()
|
|
136
138
|
|
|
139
|
+
if args.user:
|
|
140
|
+
logging.debug("REST API Password Length: %s", len(password))
|
|
141
|
+
|
|
137
142
|
# process args, setup connection:
|
|
138
143
|
rest_url = args.rest_url
|
|
139
144
|
|
|
@@ -145,12 +150,16 @@ def get_besapi_connection(args):
|
|
|
145
150
|
if args.user and password:
|
|
146
151
|
try:
|
|
147
152
|
bes_conn = besapi.besapi.BESConnection(args.user, password, rest_url)
|
|
148
|
-
# bes_conn.login()
|
|
149
153
|
except (
|
|
150
154
|
AttributeError,
|
|
151
155
|
ConnectionRefusedError,
|
|
152
156
|
besapi.besapi.requests.exceptions.ConnectionError,
|
|
153
157
|
):
|
|
158
|
+
logging.exception(
|
|
159
|
+
"connection to `%s` failed, attempting `%s` instead",
|
|
160
|
+
rest_url,
|
|
161
|
+
args.besserver,
|
|
162
|
+
)
|
|
154
163
|
try:
|
|
155
164
|
# print(args.besserver)
|
|
156
165
|
bes_conn = besapi.besapi.BESConnection(
|
|
@@ -159,8 +168,22 @@ def get_besapi_connection(args):
|
|
|
159
168
|
# handle case where args.besserver is None
|
|
160
169
|
# AttributeError: 'NoneType' object has no attribute 'startswith'
|
|
161
170
|
except AttributeError:
|
|
162
|
-
|
|
171
|
+
logging.exception("----- ERROR: BigFix Connection Failed ------")
|
|
172
|
+
logging.exception(
|
|
173
|
+
"attempts to connect to BigFix using rest_url and besserver both failed"
|
|
174
|
+
)
|
|
175
|
+
return None
|
|
176
|
+
except BaseException as err:
|
|
177
|
+
# always log error and stop the current process
|
|
178
|
+
logging.exception("ERROR: %s", err)
|
|
179
|
+
logging.exception(
|
|
180
|
+
"----- ERROR: BigFix Connection Failed! Unknown reason ------"
|
|
181
|
+
)
|
|
182
|
+
return None
|
|
163
183
|
else:
|
|
184
|
+
logging.info(
|
|
185
|
+
"attempting connection to BigFix using config file method as user command arg was not provided"
|
|
186
|
+
)
|
|
164
187
|
bes_conn = besapi.besapi.get_bes_conn_using_config_file()
|
|
165
188
|
|
|
166
189
|
return bes_conn
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|