@@ -0,0 +1,2168 @@
+from sauna.plugins import Plugin, PluginRegister%0A%0Amy_plugin = PluginRegister('Apt')%0A%0A%0A@my_plugin.plugin()%0Aclass AptPlugin(Plugin):%0A%0A    def __init__(self, config):%0A        super().__init__(config)%0A        try:%0A            import apt%0A            self._apt = apt%0A        except ImportError:%0A            from ... import DependencyError%0A            raise DependencyError(%0A                self.__class__.__name__,%0A                'apt',%0A                deb='python3-apt'%0A            )%0A        self._packages = None%0A%0A    @property%0A    def packages(self) -%3E list:%0A        if self._packages is None:%0A            with self._apt.Cache() as cache:%0A                cache.upgrade()  # Only reads the packages to upgrade%0A                self._packages = cache.get_changes()%0A        return self._packages%0A%0A    @my_plugin.check()%0A    def security_updates(self, check_config):%0A        num_security_packages = 0%0A        for p in self.packages:%0A            for o in p.candidate.origins:%0A                if 'security' in o.codename.lower():%0A                    num_security_packages += 1%0A                    break%0A%0A                if 'security' in o.label.lower():%0A                    num_security_packages += 1%0A                    break%0A%0A                if 'security' in o.site.lower():%0A                    num_security_packages += 1%0A                    break%0A%0A        if num_security_packages == 0:%0A            return self.STATUS_OK, 'No security updates'%0A%0A        return (%0A            self.STATUS_WARN,%0A            f'%7Bnum_security_packages%7D packages with security updates'%0A        )%0A%0A    @my_plugin.check()%0A    def package_updates(self, check_config):%0A        if not self.packages:%0A            return self.STATUS_OK, 'No package updates'%0A%0A        return (%0A            self.STATUS_WARN,%0A            f'%7Blen(self.packages)%7D packages updates'%0A        )%0A%0A    @staticmethod%0A    def config_sample():%0A        return '''%0A        # Debian APT%0A        # This only consults the local APT cache, it does not%0A        # run an 'apt update'. Use 'unattended-upgrades' for that.%0A        - type: Apt%0A          checks:%0A            - type: security_updates%0A            - type: package_updates%0A        '''%0A

Add APT plugin to alert of Debian security updates