Commit bdcd72c5 authored by Bonnegent's avatar Bonnegent
Browse files

version initialie

parents
En bref
=======
Présente quelques informations simples sur le système d'exploitation:
- distribution
- version
- charge CPU sur 5mn
Installation
============
Linux
-----
$ adduser osinfo
$ cp osinfo.service /etc/systemd/system/
$ systemctl start osinfo
$ systemctl enable osinfo
Windows
-------
À faire.
Lancement manuel
================
$ ./osinfo.py
Voir le résultat dans un navigateur sur http://ip_de_la_machine:7777
#!/usr/bin/env python3
from http.server import BaseHTTPRequestHandler, HTTPServer
import platform
import os
PORT = 7777
VERSION = "17.12.18"
class MyServer(BaseHTTPRequestHandler):
# GET is for clients geting the predi
def do_GET(self):
"""Va retourner les informations suivantes sur une même ligne,
en utilisant un ';' comme séparateur.
On a mis de côté les infos suivantes car non multiplateforme par défaut
- nombre d'utilisateur connecté
- uptime
Exemple:
os;os_version;état;charge
"""
self.send_response(200)
os = self.get_os()
os_version = self.get_os_version()
# state = self.get_state()
load = self.get_load()
message = "%s;%s;%s" % (os, os_version, load)
self.wfile.write(bytes(message, "utf-8"))
def get_os(self):
try:
distrib = platform.dist()
# linux = ('Fedora', '26', 'Twenty Six')
except Exception:
name = "inconnue"
else:
name = " ".join(distrib[:2])
return name
def get_os_version(self):
file_version = "/etc/version"
try:
fd = open(file_version, 'r')
tmp = fd.readline().split('\n')[0]
except Exception:
version = 'inconnue'
else:
version = tmp
return version
def get_state(self):
state = 'O'
return state
def get_load(self):
try:
load = os.getloadavg()[1]
except Exception:
load = "inconnue"
return load
def usage():
print('Usage: la_commande_sans_argument')
def run(server_class=HTTPServer, handler_class=MyServer, port=PORT):
server_address = ('', port)
httpd = server_class(server_address, handler_class)
print("Starting OSInfo [%s] ..." % VERSION)
httpd.serve_forever()
if __name__ == "__main__":
from sys import argv
if len(argv) == 1:
run()
# run(port=int(argv[1]))
else:
usage()
[Unit]
Description=OS Info
After=syslog.target network.target
[Service]
Type=simple
User=osinfo
Group=osinfo
ExecStart=/opt/osinfo/osinfo.py
[Install]
WantedBy=multi-user.target
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment