Skip to content

Commit 03a8a17

Browse files
authored
Remove the confusing --verbose vs. --debug CLI options and log more. (#106)
* Remove the confusing `--verbose` vs. `--debug` CLI options and log more. This sets the default loglevel to INFO (was CRITICAL) and reworks all of the sal-submit logging to make more stuff INFO. It then removes the `--verbose` arg. This was originally meant to not spew a bunch of Sal stuff at the end of Munki runs, but we've subsequently decoupled Sal submissions from Munki, so that's not really a goal any longer. * Bump version
1 parent 8cf04ba commit 03a8a17

File tree

2 files changed

+29
-33
lines changed

2 files changed

+29
-33
lines changed

payload/usr/local/sal/bin/sal-submit

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,16 @@ def main():
3030
log_level = get_log_level(args)
3131
logging.basicConfig(level=log_level, format="%(asctime)s %(levelname)s %(message)s")
3232
logging.info("%s Version: %s", os.path.basename(__file__), sal.__version__)
33-
if log_level == logging.DEBUG:
34-
logging.debug("Sal client prefs:")
35-
prefs = sal.prefs_report()
36-
if args.url:
37-
prefs["ServerURL"] = {"value": args.url, "forced": "commandline"}
38-
if args.key:
39-
prefs["key"] = {"value": args.key, "forced": "commandline"}
40-
for k, v in prefs.items():
41-
logging.debug(
42-
f'\t{k}: {v["value"]} ({"profile" if v["forced"] else "prefs"})'
43-
)
33+
logging.info("Sal client prefs:")
34+
prefs = sal.prefs_report()
35+
if args.url:
36+
prefs["ServerURL"] = {"value": args.url, "forced": "commandline"}
37+
if args.key:
38+
prefs["key"] = {"value": args.key, "forced": "commandline"}
39+
for k, v in prefs.items():
40+
logging.info(
41+
f'\t{k}: {v["value"]} ({"profile" if v["forced"] else "prefs"})'
42+
)
4443

4544
exit_if_not_root()
4645
if sal.wait_for_script("sal-submit"):
@@ -51,7 +50,7 @@ def main():
5150
logging.info("Processing checkin modules...")
5251
script_results = sal.run_scripts(CHECKIN_MODULES_DIR)
5352
for message in script_results:
54-
logging.debug(message)
53+
logging.info(message)
5554

5655
submission = sal.get_checkin_results()
5756
run_type = get_run_type(submission)
@@ -65,16 +64,15 @@ def main():
6564
sal.setup_sal_client()
6665
if args.url:
6766
sal.get_sal_client().base_url = args.url
68-
logging.debug("Server URL overridden with %s", args.url)
67+
logging.info("Server URL overridden with %s", args.url)
6968

7069
if args.key:
7170
sesh = sal.get_sal_client().auth = ("sal", args.key)
7271
# Override the key in the report, since it's used for querying.
7372
report["Sal"]["extra_data"]["key"] = args.key
74-
logging.debug("Machine group key overridden with %s", args.key)
75-
if logging.getLogger().level <= 10:
76-
logging.debug("Checkin submission:")
77-
logging.debug(json.dumps(report, indent=4, default=sal.serializer))
73+
logging.info("Machine group key overridden with %s", args.key)
74+
logging.debug("Checkin submission:")
75+
logging.debug(json.dumps(report, indent=4, default=sal.serializer))
7876
response = send_checkin(report)
7977

8078
if response and response.status_code == 200:
@@ -95,11 +93,9 @@ def main():
9593

9694
def get_log_level(args):
9795
"""Set the verbosity based on options."""
98-
loglevel = logging.CRITICAL
96+
loglevel = logging.INFO
9997
if args.debug:
10098
loglevel = logging.DEBUG
101-
elif args.verbose:
102-
loglevel = logging.INFO
10399
return loglevel
104100

105101

@@ -118,7 +114,7 @@ def get_args():
118114
"--verbose",
119115
default=False,
120116
action="store_true",
121-
help="Enable verbose output.",
117+
help="Deprecated. Does nothing",
122118
)
123119
parser.add_argument(
124120
"-u", "--url", default=None, help="Override the server URL for testing."
@@ -167,7 +163,7 @@ def run_external_scripts(run_type):
167163
stdout=subprocess.PIPE,
168164
stderr=subprocess.PIPE,
169165
)
170-
logging.debug("%s ran successfully.", script)
166+
logging.info("%s ran successfully.", script)
171167
except OSError:
172168
logging.warning("Couldn't run %s", script)
173169
except subprocess.CalledProcessError:
@@ -254,12 +250,12 @@ def sanitize_submission():
254250

255251

256252
def send_checkin(report):
257-
logging.debug("Sending report")
253+
logging.info("Sending report")
258254
try:
259255
response = sal.get_sal_client().post("checkin/", json=report)
260256
except requests.exceptions.RequestException as error:
261257
logging.error("Failed to send report")
262-
logging.debug(error)
258+
logging.error(error)
263259
response = None
264260
return response
265261

@@ -270,18 +266,18 @@ def send_inventory(serial):
270266
"ManagedInstalls", "ManagedInstallDir", "/Library/Managed Installs"
271267
)
272268
inventory_plist = pathlib.Path(managed_install_dir) / "ApplicationInventory.plist"
273-
logging.debug("ApplicationInventory.plist Path: %s", inventory_plist)
269+
logging.info("ApplicationInventory.plist Path: %s", inventory_plist)
274270

275271
if inventory := inventory_plist.read_bytes():
276272
inventory_hash = sal.get_hash(inventory_plist)
277-
logging.debug(f"Inventory hash: {inventory_hash}")
273+
logging.info(f"Inventory hash: {inventory_hash}")
278274
serverhash = None
279275
sal_client = sal.get_sal_client()
280276
try:
281277
response = sal_client.get(f"inventory/hash/{serial}/")
282278
except requests.exceptions.RequestException as error:
283279
logging.error("Failed to get inventory hash")
284-
logging.debug(error)
280+
logging.error(error)
285281
return
286282
if response.status_code == 200 and response.text != inventory_hash:
287283
logging.info("Inventory is out of date; submitting...")
@@ -293,7 +289,7 @@ def send_inventory(serial):
293289
sal_client.post("inventory/submit/", data=inventory_submission)
294290
except requests.exceptions.RequestException as error:
295291
logging.error("Failed to submit inventory")
296-
logging.debug(error)
292+
logging.error(error)
297293

298294

299295
def send_catalogs():
@@ -325,7 +321,7 @@ def send_catalogs():
325321
response = sal_client.post("catalog/hash/", data=hash_submission)
326322
except requests.exceptions.RequestException as error:
327323
logging.error("Failed to get catalog hashes")
328-
logging.debug(error)
324+
logging.error(error)
329325
return
330326

331327
try:
@@ -343,12 +339,12 @@ def send_catalogs():
343339
"sha256hash": catalog["sha256hash"],
344340
}
345341

346-
logging.debug("Submitting Catalog: %s", catalog["name"])
342+
logging.info("Submitting Catalog: %s", catalog["name"])
347343
try:
348344
sal_client.post("catalog/submit/", data=catalog_submission)
349345
except requests.exceptions.RequestException as error:
350346
logging.error("Error while submitting Catalog: %s", catalog["name"])
351-
logging.debug(error)
347+
logging.error(error)
352348

353349

354350
def send_profiles(serial):
@@ -381,7 +377,7 @@ def send_profiles(serial):
381377
sal.get_sal_client().post("profiles/submit/", data=profile_submission)
382378
except requests.exceptions.RequestException as error:
383379
logging.error("Failed to submit profiles")
384-
logging.debug(error)
380+
logging.error(error)
385381

386382

387383
def _payload_cleanse(payload):

sal_python_pkg/sal/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "4.6.0"
1+
__version__ = "4.7.0"

0 commit comments

Comments
 (0)