mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 17:50:20 +00:00
Notify beacon for Debian/Ubuntu systems (#347)
Signed-off-by: Ricardo Mateus <rmateus@suse.com> (cherry picked from commit 33d6baebba94cc7a66d5555de984ca98684157a0)
This commit is contained in:
parent
de169b3a4d
commit
75a13bf3f5
3 changed files with 54 additions and 0 deletions
1
scripts/suse/dpkg/99dpkgnotify
Normal file
1
scripts/suse/dpkg/99dpkgnotify
Normal file
|
@ -0,0 +1 @@
|
|||
DPkg::Post-Invoke {"/usr/bin/dpkgnotify";};
|
9
scripts/suse/dpkg/README.md
Normal file
9
scripts/suse/dpkg/README.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
## What it is
|
||||
|
||||
Debian base package to notify installation of new packages outside the control of salt.
|
||||
|
||||
## Installation
|
||||
This script depends on python package, so python3 should be installed on the machine
|
||||
|
||||
- The 99dpkgnotify file must be installed in /etc/apt/apt.conf.d/99dpkgnotify
|
||||
- The dpkgnotify file must be installed in /usr/bin/dpkgnotify
|
44
scripts/suse/dpkg/dpkgnotify
Normal file
44
scripts/suse/dpkg/dpkgnotify
Normal file
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import os
|
||||
import hashlib
|
||||
|
||||
CK_PATH = "/var/cache/salt/minion/dpkg.cookie"
|
||||
DPKG_PATH = "/var/lib/dpkg/status"
|
||||
|
||||
def _get_mtime():
|
||||
"""
|
||||
Get the modified time of the Package Database.
|
||||
Returns:
|
||||
Unix ticks
|
||||
"""
|
||||
return os.path.exists(DPKG_PATH) and int(os.path.getmtime(DPKG_PATH)) or 0
|
||||
|
||||
|
||||
def _get_checksum():
|
||||
"""
|
||||
Get the checksum of the Package Database.
|
||||
Returns:
|
||||
hexdigest
|
||||
"""
|
||||
digest = hashlib.sha256()
|
||||
with open(DPKG_PATH, "rb") as pkg_db_fh:
|
||||
while True:
|
||||
buff = pkg_db_fh.read(0x1000)
|
||||
if not buff:
|
||||
break
|
||||
digest.update(buff)
|
||||
return digest.hexdigest()
|
||||
|
||||
|
||||
def dpkg_post_invoke():
|
||||
"""
|
||||
Hook after the package installation transaction.
|
||||
"""
|
||||
if 'SALT_RUNNING' not in os.environ:
|
||||
with open(CK_PATH, 'w') as ck_fh:
|
||||
ck_fh.write('{chksum} {mtime}\n'.format(chksum=_get_checksum(), mtime=_get_mtime()))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
dpkg_post_invoke()
|
Loading…
Add table
Reference in a new issue