Added icon.png
This commit is contained in:
parent
f08c99800d
commit
9ebad5610e
3 changed files with 132 additions and 44 deletions
BIN
pastafaristats/icon.png
Normal file
BIN
pastafaristats/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.4 KiB |
|
|
@ -5,6 +5,28 @@ from pastafaristats import send_info_daemon
|
||||||
from time import sleep
|
from time import sleep
|
||||||
import os
|
import os
|
||||||
import psutil
|
import psutil
|
||||||
|
from pathlib import Path
|
||||||
|
import signal
|
||||||
|
|
||||||
|
#Get user_home and environment variables
|
||||||
|
|
||||||
|
user_home=str(Path.home())
|
||||||
|
|
||||||
|
path_config=user_home+'/.config/pastafari/stats.cfg'
|
||||||
|
|
||||||
|
# Create configuration
|
||||||
|
|
||||||
|
Path(os.path.dirname(path_config)).mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
if not os.path.isfile(path_config):
|
||||||
|
config_data="""[DEFAULT]
|
||||||
|
url_server={}
|
||||||
|
""".format('http://localhost:5000/api_token')
|
||||||
|
|
||||||
|
with open(path_config, 'w') as f:
|
||||||
|
f.write(config_data)
|
||||||
|
|
||||||
|
# Get functions
|
||||||
|
|
||||||
def quit_app():
|
def quit_app():
|
||||||
print('Quitting Application...')
|
print('Quitting Application...')
|
||||||
|
|
@ -31,12 +53,18 @@ def quit_app():
|
||||||
# Killing using pid
|
# Killing using pid
|
||||||
|
|
||||||
#p.stop()
|
#p.stop()
|
||||||
|
def show_config_win():
|
||||||
|
|
||||||
|
winconfig.show()
|
||||||
|
|
||||||
def send_data():
|
def send_data():
|
||||||
print('Init daemon...')
|
print('Init daemon...')
|
||||||
|
|
||||||
|
url_monit=send_info_daemon.load_config()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
send_info_daemon.run()
|
send_info_daemon.run(url_monit)
|
||||||
|
|
||||||
sleep(120)
|
sleep(120)
|
||||||
|
|
||||||
|
|
@ -61,6 +89,37 @@ class ProcessRunnable(QRunnable):
|
||||||
print('Stopping daemon...')
|
print('Stopping daemon...')
|
||||||
del self.t
|
del self.t
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
class WinConfig(QWidget):
|
||||||
|
def __init__(self, url_monit='http://192.168.1.51/monit'):
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
url_monit=send_info_daemon.load_config()
|
||||||
|
|
||||||
|
self.text=QLabel("Change monitoritation url, example: http://192.168.1.51/monit/api_token")
|
||||||
|
self.input=QLineEdit(url_monit)
|
||||||
|
self.button=QPushButton("Save")
|
||||||
|
|
||||||
|
self.layout=QVBoxLayout(self)
|
||||||
|
self.layout.addWidget(self.text)
|
||||||
|
self.layout.addWidget(self.input)
|
||||||
|
self.layout.addWidget(self.button)
|
||||||
|
|
||||||
|
self.button.clicked.connect(self.save_config)
|
||||||
|
|
||||||
|
|
||||||
|
def save_config(self):
|
||||||
|
|
||||||
|
config_data="""[DEFAULT]
|
||||||
|
url_server={}
|
||||||
|
""".format(self.input.text())
|
||||||
|
|
||||||
|
with open(path_config, 'w') as f:
|
||||||
|
f.write(config_data)
|
||||||
|
|
||||||
|
print('Config saved...')
|
||||||
|
|
||||||
|
self.hide()
|
||||||
|
|
||||||
app = QApplication([])
|
app = QApplication([])
|
||||||
app.setQuitOnLastWindowClosed(False)
|
app.setQuitOnLastWindowClosed(False)
|
||||||
|
|
@ -79,10 +138,10 @@ menu = QMenu()
|
||||||
|
|
||||||
option1 = QAction("Pastafari monitoring")
|
option1 = QAction("Pastafari monitoring")
|
||||||
menu.addAction(option1)
|
menu.addAction(option1)
|
||||||
"""
|
|
||||||
option2 = QAction("GFG")
|
option2 = QAction("Setup Monitoring url")
|
||||||
|
option2.triggered.connect(show_config_win)
|
||||||
menu.addAction(option2)
|
menu.addAction(option2)
|
||||||
"""
|
|
||||||
|
|
||||||
# To quit the app
|
# To quit the app
|
||||||
quit = QAction("Quit")
|
quit = QAction("Quit")
|
||||||
|
|
@ -92,11 +151,30 @@ menu.addAction(quit)
|
||||||
# Adding options to the System Tray
|
# Adding options to the System Tray
|
||||||
tray.setContextMenu(menu)
|
tray.setContextMenu(menu)
|
||||||
|
|
||||||
|
# Prepare url monitoritation
|
||||||
|
|
||||||
|
winconfig=WinConfig()
|
||||||
|
|
||||||
|
winconfig.resize(400, 200)
|
||||||
|
|
||||||
# Begin background process
|
# Begin background process
|
||||||
|
|
||||||
p = ProcessRunnable(target=send_data, args=())
|
p = ProcessRunnable(target=send_data, args=())
|
||||||
p.start()
|
p.start()
|
||||||
|
|
||||||
|
# Catch sigint
|
||||||
|
|
||||||
|
def catch_signal(sig, frame):
|
||||||
|
print('Exiting from app...')
|
||||||
|
pid=os.getpid()
|
||||||
|
|
||||||
|
p=psutil.Process(pid)
|
||||||
|
|
||||||
|
p.terminate()
|
||||||
|
exit(0)
|
||||||
|
|
||||||
|
signal.signal(signal.SIGINT, catch_signal)
|
||||||
|
|
||||||
# Begin tray loop
|
# Begin tray loop
|
||||||
|
|
||||||
app.exec_()
|
app.exec_()
|
||||||
|
|
|
||||||
|
|
@ -14,45 +14,45 @@ import signal
|
||||||
|
|
||||||
#url="http://url/to/info"
|
#url="http://url/to/info"
|
||||||
|
|
||||||
# Get config from /etc/pastafari or ~/.config/pastafari
|
|
||||||
|
|
||||||
# Load configuration
|
|
||||||
|
|
||||||
yes_config=False
|
|
||||||
|
|
||||||
user_home=str(Path.home())
|
user_home=str(Path.home())
|
||||||
|
|
||||||
config = configparser.ConfigParser(interpolation=None)
|
def load_config():
|
||||||
|
|
||||||
|
yes_config=False
|
||||||
|
|
||||||
|
config = configparser.ConfigParser(interpolation=None)
|
||||||
|
|
||||||
if os.path.isfile(user_home+'/.config/pastafari/stats.cfg'):
|
if os.path.isfile(user_home+'/.config/pastafari/stats.cfg'):
|
||||||
|
|
||||||
config.read(user_home+'/.config/pastafari/stats.cfg')
|
config.read(user_home+'/.config/pastafari/stats.cfg')
|
||||||
|
|
||||||
yes_config=True
|
yes_config=True
|
||||||
|
|
||||||
elif os.path.isfile('/etc/pastafari/stats.cfg'):
|
elif os.path.isfile('/etc/pastafari/stats.cfg'):
|
||||||
|
|
||||||
|
config.read('/etc/pastafari/stats.cfg')
|
||||||
|
|
||||||
|
yes_config=True
|
||||||
|
|
||||||
config.read('/etc/pastafari/stats.cfg')
|
if not yes_config:
|
||||||
|
|
||||||
yes_config=True
|
exit("Sorry, cannot load config file")
|
||||||
|
|
||||||
|
|
||||||
if not yes_config:
|
|
||||||
|
|
||||||
exit("Sorry, cannot load config file")
|
|
||||||
|
|
||||||
if not 'DEFAULT' in config:
|
if not 'DEFAULT' in config:
|
||||||
|
|
||||||
exit("Sorry, config file need [DEFAULT] section")
|
exit("Sorry, config file need [DEFAULT] section")
|
||||||
|
|
||||||
if not 'url_server' in config['DEFAULT']:
|
if not 'url_server' in config['DEFAULT']:
|
||||||
|
|
||||||
|
exit("Sorry, config file need url_server variable in [DEFAULT] section")
|
||||||
|
|
||||||
|
url=config['DEFAULT']['url_server']
|
||||||
|
|
||||||
exit("Sorry, config file need url_server variable in [DEFAULT] section")
|
return url
|
||||||
|
|
||||||
|
|
||||||
|
def run(url):
|
||||||
|
|
||||||
url=config['DEFAULT']['url_server']
|
|
||||||
|
|
||||||
def run():
|
|
||||||
|
|
||||||
network_info=psutil.net_io_counters(pernic=False)
|
network_info=psutil.net_io_counters(pernic=False)
|
||||||
|
|
||||||
network_devices=psutil.net_if_addrs()
|
network_devices=psutil.net_if_addrs()
|
||||||
|
|
@ -102,22 +102,32 @@ def run():
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
||||||
print('Cannot connect to data server -> '+str(e))
|
print('Cannot connect to data server -> '+str(e))
|
||||||
|
|
||||||
|
#Reload config
|
||||||
|
url=load_config()
|
||||||
|
|
||||||
|
|
||||||
|
def start(url):
|
||||||
|
|
||||||
|
# Get config from /etc/pastafari or ~/.config/pastafari
|
||||||
|
|
||||||
|
# Load configuration
|
||||||
|
|
||||||
def start():
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
run()
|
run(url)
|
||||||
|
|
||||||
sleep(120)
|
sleep(120)
|
||||||
|
|
||||||
def catch_signal(sig, frame):
|
|
||||||
print('Exiting...')
|
|
||||||
exit(0)
|
|
||||||
|
|
||||||
signal.signal(signal.SIGINT, catch_signal)
|
|
||||||
|
|
||||||
if __name__=='__main__':
|
if __name__=='__main__':
|
||||||
|
|
||||||
start()
|
def catch_signal(sig, frame):
|
||||||
|
print('Exiting...')
|
||||||
|
exit(0)
|
||||||
|
|
||||||
|
signal.signal(signal.SIGINT, catch_signal)
|
||||||
|
|
||||||
|
url=load_config()
|
||||||
|
|
||||||
|
start(url)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue