diff --git a/zypper.py b/zypper.py new file mode 100755 index 0000000..9b6b1be --- /dev/null +++ b/zypper.py @@ -0,0 +1,129 @@ +#!/usr/bin/env python3 + +""" +Description: #TODO: short version + +#TODO: long version + +#TODO: example + + #TODO: code of the example + +#TODO: additional information + +Dependencies: python3-apt + +Authors: Gabriele Puliti + Bernd Shubert <@suse.org> +""" + +from __future__ import annotations + +import argparse +from collections.abc import Sequence + +def get_pending_updates(zypper_output): + return None + +def get_updates_sum(zypper_output): + return None + +def get_pending_patches(zypper_output): + return None + +def get_patches_sum(zypper_output): + return None + +def get_pending_security_patches(zypper_output): + return None + +def get_pending_security_important_patches(zypper_output): + return None + +def get_pending_reboot_patches(zypper_output): + return None + +def get_zypper_version(zypper_output): + return None + +def get_orphan_packages(zypper_output): + return None + + +def main(argv: Sequence[str] | None = None) -> int: + parser = argparse.ArgumentParser() + parser.add_mutually_exclusive_group(required=False) + parser.add_argument( + "-m", + "--more", + dest="all_info", + action='store_true', + help="Print all the package infos", + ) + parser.add_argument( + "-l", + "--less", + dest="all_info", + action='store_false', + help="Print less package infos", + ) + parser.set_defaults(all_info=True) + args = parser.parse_args(argv) + + print(f"{args.all_info}") + # If there are no paramenter passed then use the more format + zypper_lu_quiet_tail_n3="$(/usr/bin/zypper --quiet lu | tail -n +3)" + zypper_lp_quiet_tail_n3="$(/usr/bin/zypper --quiet lp | sed -E '/(^$|^Repository|^---)/d'| sed '/|/!d')" + zypper_version="$(/usr/bin/zypper -V)" + zypper_orphan_packages="$(zypper --quiet pa --orphaned | tail -n +3)" + + print('# HELP zypper_update_pending zypper package update available from repository. (0 = not available, 1 = available)') + print('# TYPE zypper_update_pending gauge') + get_pending_updates(zypper_lu_quiet_tail_n3) + + print('# HELP zypper_updates_pending_total zypper packages updates available in total') + print('# TYPE zypper_updates_pending_total counter') + get_updates_sum(zypper_lu_quiet_tail_n3) + + print('# HELP zypper_patch_pending zypper patch available from repository. (0 = not available, 1 = available)') + print('# TYPE zypper_patch_pending gauge') + get_pending_patches(zypper_lp_quiet_tail_n3) + + print('# HELP zypper_patches_pending_total zypper patches available total') + print('# TYPE zypper_patches_pending_total counter') + get_patches_sum(zypper_lp_quiet_tail_n3) + + print('# HELP zypper_patches_pending_security_total zypper patches available with category security total') + print('# TYPE zypper_patches_pending_security_total counter') + get_pending_security_patches(zypper_lp_quiet_tail_n3) + + print('# HELP zypper_patches_pending_security_important_total zypper patches available with category security severity important total') + print('# TYPE zypper_patches_pending_security_important_total counter') + get_pending_security_important_patches(zypper_lp_quiet_tail_n3) + + print('# HELP zypper_patches_pending_reboot_total zypper patches available which require reboot total') + print('# TYPE zypper_patches_pending_reboot_total counter') + get_pending_reboot_patches(zypper_lp_quiet_tail_n3) + + # TODO: + #if [[ -x /usr/bin/needs-restarting ]] + # print('# HELP node_reboot_required Node require reboot to active installed updates or patches. (0 = not needed, 1 = needed)') + # print('# TYPE node_reboot_required gauge') + # if /usr/bin/needs-restarting -r >/dev/null 2>&1; then + # print('node_reboot_required 0') + # else + # print('node_reboot_required 1') + + print('# HELP zypper_version zypper installed package version') + print('# TYPE zypper_version gauges') + get_zypper_version("$zypper_version") + + print('# HELP zypper_package_orphan zypper packages with no update source (orphaned)') + print('# TYPE zypper_package_orphan gauges') + get_orphan_packages("$zypper_orphan_packages") + + return 0 + + +if __name__ == "__main__": + raise SystemExit(main())