update systemd files

This commit is contained in:
Justin Hammond 2015-10-23 23:02:30 +08:00
parent 7362cb1063
commit ee87fc8efe
4 changed files with 74 additions and 13 deletions

7
dist/LMBd.spec vendored
View file

@ -5,7 +5,7 @@ URL: https://github.com/Fishwaldo/LEDMessageBoard
License: GPL
Version: 1.0.1445180435.6a453c9
Release: 0
BuildRequires: gcc-c++ cmake boost-devel boost-thread boost-filesystem boost-program-options
BuildRequires: gcc-c++ cmake boost-devel boost-thread boost-filesystem boost-program-options systemd
Source0: LMBd-%{version}.tar.gz
@ -26,6 +26,9 @@ make %{?_smp_mflags}
make install DESTDIR=${RPM_BUILD_ROOT} && cd ..
mkdir -p ${RPM_BUILD_ROOT}/var/spool/LMBd
mkdir -p ${RPM_BUILD_ROOT}/var/log/LMBd
cp scripts/zabbix-stats.service %{_unitdir}
cp scripts/lmbd.service %{_unitdir}
%files
%defattr(-,root,root,-)
@ -35,6 +38,8 @@ mkdir -p ${RPM_BUILD_ROOT}/var/log/LMBd
%config /etc/zabbix_stats.cfg
%dir /var/spool/LMBd
%dir /var/log/LMBd
%{_unitdir}/*.service
#%doc README
#%config /etc/ozwwebapp/*

16
scripts/lmbd.service Normal file
View file

@ -0,0 +1,16 @@
[Unit]
Description=lmbd
After=syslog.target
After=network.target
[Service]
Type=simple
User=nobody
Group=nobody
ExecStart=/usr/bin/LMBd --config /etc/LMBd.conf
# Give the script some time to startup
TimeoutSec=300
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,17 @@
[Unit]
Description=Zabbix-Stats
After=syslog.target
After=network.target
Requires=lmbd.service
[Service]
Type=simple
User=nobody
Group=nobody
ExecStart=/usr/bin/python /usr/bin/zabbix_stats.py -c /etc/zabbix_stats.cfg
# Give the script some time to startup
TimeoutSec=300
[Install]
WantedBy=multi-user.target

View file

@ -11,22 +11,42 @@ import time
import pprint
import re
import ConfigParser
import getopt
import sys
pp = pprint.PrettyPrinter(indent=4)
config = ConfigParser.ConfigParser()
config.read('zabbix_stats.cfg')
def main(argv):
cfgfile = "/etc/zabbix_stats.cfg"
try:
opts, args = getopt.getopt(argv, "hc:", ["configfile="])
except getopt.GetoptError:
print 'zabbix_stats.py -c <configfile>'
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print 'zabbix_stats.py -c <configfile>'
sys.exit(2)
elif opt in ("-c", "--configfile"):
cfgfile = arg
pp = pprint.PrettyPrinter(indent=4)
config = ConfigParser.ConfigParser()
config.read(cfgfile)
global zapi
zapi = ZabbixAPI(config.get('Server', 'zabbixurl'))
zapi.session.verify = False
# Login to the Zabbix API
zapi.login(config.get('Server', 'username'), config.get('Server', 'password'))
while(1):
Alerts()
# The hostname at which the Zabbix web interface is available
ZABBIX_SERVER = 'http://10.1.1.7/zabbix/'
zapi = ZabbixAPI(config.get('Server', 'zabbixurl'))
zapi.session.verify = False
# Login to the Zabbix API
zapi.login(config.get('Server', 'username'), config.get('Server', 'password'))
def Stats():
global zapi
BWVals = {}
results = {}
BWVals['MikroTik'] = {'key':{'if*Octets[Wan2 - Client]', 'if*Octets[Wan1 - Server]'}, 'limit':10}
@ -95,6 +115,7 @@ def Stats():
def Alerts():
# Get a list of all issues (AKA tripped triggers)
global zapi
triggers = zapi.trigger.get(only_true=1,
skipDependent=1,
monitored=1,
@ -131,5 +152,7 @@ def Alerts():
f3.close()
time.sleep(60)
while(1):
Alerts()
if __name__ == "__main__":
main(sys.argv[1:])