Skip to content

Commit

Permalink
Changed apt to dpkg
Browse files Browse the repository at this point in the history
  • Loading branch information
dparv committed Jan 19, 2023
1 parent 0f4ec0e commit 340e5f5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 8 additions & 8 deletions exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Exporter(BaseHTTPRequestHandler):

def _set_response(self):
self.send_response(200)
if self.path in ['/apt', '/snap', '/kernel']:
if self.path in ['/dpkg', '/snap', '/kernel']:
self.send_header('Content-type', 'application/json')
else:
self.send_header('Content-type', 'text/html')
Expand All @@ -21,8 +21,8 @@ def do_GET(self):
self._set_response()
if self.path == '/hostname':
self.wfile.write(socket.gethostname().encode("utf-8"))
elif self.path == '/apt':
self.wfile.write(self.generate_apt_output().encode("utf-8"))
elif self.path == '/dpkg':
self.wfile.write(self.generate_dpkg_output().encode("utf-8"))
elif self.path == '/snap':
self.wfile.write(self.generate_snap_output().encode("utf-8"))
elif self.path == '/kernel':
Expand All @@ -31,19 +31,19 @@ def do_GET(self):
helper= """
<a href='/hostname'>/hostname</a>
<br />
<a href='/apt'>/apt</a>
<a href='/dpkg'>/dpkg</a>
<br />
<a href='/snap'>/snap</a>
<br />
<a href='/kernel'>/kernel</a>
"""
self.wfile.write(helper.encode("utf-8"))

def generate_apt_output(self):
def generate_dpkg_output(self):
cmd = 'dpkg -l --admindir=/var/lib/snapd/hostfs/var/lib/dpkg'
apts = subprocess.check_output(cmd.split())
apts = str(apts)
lines = apts.split('\\n')
dpkg = subprocess.check_output(cmd.split())
dpkg = str(dpkg)
lines = dpkg.split('\\n')
lines = lines[5:-1]
output = []
for line in lines:
Expand Down
2 changes: 2 additions & 0 deletions snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ parts:
exporter:
plugin: dump
source: .
stage-packages:
- dpkg

apps:
inventory-exporter:
Expand Down

0 comments on commit 340e5f5

Please sign in to comment.