From: Stephen Soltesz Date: Thu, 4 Dec 2008 22:21:20 +0000 (+0000) Subject: fixed the httpd conf issue with redirecting to /monitor/ X-Git-Tag: Monitor-2.0-0~15 X-Git-Url: http://git.onelab.eu/?p=monitor.git;a=commitdiff_plain;h=786822939c1d244e30172b997f91dd4aafb2ff24;ds=sidebyside fixed the httpd conf issue with redirecting to /monitor/ added styles for severity levels on node actions from zabbix added extra class definitions to zabbixapi/model.py for event queries added ack'd/non-ack'd action view based on zabbix db. --- diff --git a/monitor-server.init b/monitor-server.init index 098ecba..28a7df8 100644 --- a/monitor-server.init +++ b/monitor-server.init @@ -242,50 +242,33 @@ function create_httpd_conf () WROTE_HTTP_CONFIG="true" fi - # TODO: make http port configurable. + # TODO: support HTTPS as well as port 80. currently not specifying port + # 80 breaks https for other content on the myplc. # TODO: make proxy port configurable. cat < ${MONITOR_HTTP_CONF} -NameVirtualHost * - - - ServerName ${PLC_MONITOR_HOST} - ServerAdmin ${PLC_MONITOR_EMAIL} - UseCanonicalName Off - ServerSignature Off - - # NOTE: this appears to alter the global document root, for port 80... - # not sure if it's possible to serve two different 'virtualhosts' from - # the same port and same hostname with different document roots... - #DocumentRoot ${MONITORPATH}/web/MonitorWeb/monitorweb - - # - # Options Indexes FollowSymLinks - # AllowOverride None - # Order allow,deny - # Allow from all - # - #LogLevel debug - Errorlog /var/log/httpd/monitorwebapp-error_log - Customlog /var/log/httpd/monitorwebapp-access_log common - - AddDefaultCharset utf-8 +# NOTE: I've tried other means of redirection, including mod_rewrite, but did +# not have any success. The means below is not idea, b/c it does not keep +# non-ssl session as non-ssl. But it works. - #NOTE: This doesn't work as expected. - # Load everything out of the DocumentRoot that is static - # ProxyPass /monitor/static ! +# NOTE: redirect path without trailing '/' to path with. Favor SSL. +Redirect /monitor https://${MONITOR_HOSTNAME}:${PLC_WWW_SSL_PORT}/monitor/ - ProxyPass /tg_js http://127.0.0.1:8080/tg_js - ProxyPassReverse /tg_js http://127.0.0.1:8080/tg_js - - ProxyPass /monitor http://127.0.0.1:8080 - ProxyPassReverse /monitor http://127.0.0.1:8080 +# NOTE: this directive strips '/monitor/' from the requested path and pastes +# the remaining part to the end of the ProxyPass url below. All TG urls +# should be relative to their current position, or the absolute path +# that includes /monitor/ at the beginning. +# TODO: make location configurable. + + #LogLevel debug + #Errorlog /var/log/httpd/monitorwebapp-error_log + #Customlog /var/log/httpd/monitorwebapp-access_log common - ProxyPreserveHost On - ProxyRequests Off + ProxyPass http://127.0.0.1:8080/ + ProxyPassReverse http://127.0.0.1:8080/ + - EOF } @@ -296,6 +279,14 @@ function start_tg_server () popd } +function stop_tg_server () +{ + pid=$( cat /var/run/monitorweb.pid ) + if [ -n "$pid" ] ; then + kill $pid + fi +} + function check_zab_server () { ZABBIXCFG=/etc/zabbix @@ -306,7 +297,7 @@ function check_zab_server () -e "s#DBName=.*#DBName=$ZABBIX_DB_NAME#g" \ -e "s#DBUser=.*#DBUser=$ZABBIX_DB_USER#g" \ -e "s#DBPassword=.*#DBPassword=$PLC_MONITOR_DBPASSWORD#g" \ - -e "s/.*ExternalScripts=.*/ExternalScripts=${MONITORPATH}\/zabbix/g" \ + -e "s#.*ExternalScripts=.*#ExternalScripts=${MONITORPATH}/zabbix#g" \ ${ZABBIXCFG}/zabbix_server.conf > $TMP_FILE cat $TMP_FILE > ${ZABBIXCFG}/zabbix_server.conf fi @@ -418,6 +409,7 @@ case "$1" in MESSAGE=$"Stopping Monitor" dialog "$MESSAGE" + stop_tg_server service zabbix_server stop service zabbix_agentd stop # TODO: is there anything to stop? diff --git a/monitor/database/dborm.py b/monitor/database/dborm.py index 5e54f11..687881a 100644 --- a/monitor/database/dborm.py +++ b/monitor/database/dborm.py @@ -9,3 +9,4 @@ mon_session = sqlalchemy.orm.scoped_session(sqlalchemy.orm.sessionmaker(autoflus zab_metadata = sqlalchemy.MetaData() zab_metadata.bind = sqlalchemy.create_engine(config.zabbix_dburi, echo=config.echo) zab_session = sqlalchemy.orm.scoped_session(sqlalchemy.orm.sessionmaker(autoflush=False,autocommit=True)) +zab_session.bind = zab_metadata.bind diff --git a/monitor/database/zabbixapi/model.py b/monitor/database/zabbixapi/model.py index 3d6bd40..35784e6 100644 --- a/monitor/database/zabbixapi/model.py +++ b/monitor/database/zabbixapi/model.py @@ -422,6 +422,42 @@ class IDs(Entity): autoload=True, ) +class Escalation(ZabbixEntity): + using_options( + tablename='escalations', + autoload=True, + auto_primarykey='escalationid' + ) + +class Event(ZabbixEntity): + using_options( + tablename='events', + autoload=True, + auto_primarykey='eventid' + ) + +class Item(ZabbixEntity): + using_options( + tablename='items', + autoload=True, + auto_primarykey='itemid' + ) + +class Acknowledge(ZabbixEntity): + using_options( + tablename='acknowledges', + autoload=True, + auto_primarykey='acknowledgeid' + ) + +class Trigger(ZabbixEntity): + using_options( + tablename='triggers', + autoload=True, + auto_primarykey='triggerid' + ) + + class Right(ZabbixEntity): # rights of a usergroup to interact with hosts of a hostgroup using_options( diff --git a/web/MonitorWeb/monitorweb/commands.py b/web/MonitorWeb/monitorweb/commands.py index 9e75f08..68df39c 100644 --- a/web/MonitorWeb/monitorweb/commands.py +++ b/web/MonitorWeb/monitorweb/commands.py @@ -2,7 +2,7 @@ """This module contains functions called from console script entry points.""" import sys -from os import getcwd +from os import getcwd, getpid from os.path import dirname, exists, join import pkg_resources @@ -45,6 +45,11 @@ def start(): except pkg_resources.DistributionNotFound: raise ConfigurationError("Could not find default configuration.") + if "prod" in configfile: + f = open("/var/run/monitorweb.pid", 'w') + f.write(str(getpid())) + f.close() + turbogears.update_config(configfile=configfile, modulename="monitorweb.config") diff --git a/web/MonitorWeb/monitorweb/controllers.py b/web/MonitorWeb/monitorweb/controllers.py index db3fbd8..be94316 100644 --- a/web/MonitorWeb/monitorweb/controllers.py +++ b/web/MonitorWeb/monitorweb/controllers.py @@ -3,9 +3,15 @@ from turbogears import controllers, expose, flash # from monitorweb import model # import logging # log = logging.getLogger("monitorweb.controllers") +import re from monitor.database.info.model import * +from monitor.database.zabbixapi.model import * +from monitor.database.dborm import zab_session as session +from monitor.database.dborm import zab_metadata as metadata + from pcucontrol import reboot from monitor.wrapper.plccache import plcdb_id2lb as site_id2lb +from monitor.wrapper.plccache import plcdb_hn2lb as site_hn2lb def format_ports(pcu): retval = [] @@ -169,7 +175,66 @@ class Root(controllers.RootController): return dict(query=query, fc=filtercount) - @expose(template="monitorweb.templates.pculist") + @expose(template="monitorweb.templates.actionlist") def action(self, filter='all'): - filtercount = {'ok' : 0, 'NetDown': 0, 'Not_Run' : 0, 'pending' : 0, 'all' : 0} - return dict(query=[], fc=filtercount) + session.bind = metadata.bind + filtercount = {'active' : 0, 'acknowledged': 0, 'all' : 0} + # With Acknowledgement + sql_ack = 'SELECT DISTINCT h.host,t.description,t.priority,t.lastchange,a.message '+ \ + ' FROM triggers t,hosts h,items i,functions f, hosts_groups hg,escalations e,acknowledges a ' + \ + ' WHERE f.itemid=i.itemid ' + \ + ' AND h.hostid=i.hostid ' + \ + ' AND hg.hostid=h.hostid ' + \ + ' AND t.triggerid=f.triggerid ' + \ + ' AND t.triggerid=e.triggerid ' + \ + ' AND a.eventid=e.eventid ' + \ + ' AND t.status=' + str(defines.TRIGGER_STATUS_ENABLED) + \ + ' AND i.status=' + str(defines.ITEM_STATUS_ACTIVE) + \ + ' AND h.status=' + str(defines.HOST_STATUS_MONITORED) + \ + ' AND t.value=' + str(defines.TRIGGER_VALUE_TRUE) + \ + ' ORDER BY t.lastchange DESC'; + + # WithOUT Acknowledgement + sql_noack = 'SELECT DISTINCT h.host,t.description,t.priority,t.lastchange,e.eventid ' + \ + ' FROM triggers t,hosts h,items i,functions f, hosts_groups hg,escalations e,acknowledges a ' + \ + ' WHERE f.itemid=i.itemid ' + \ + ' AND h.hostid=i.hostid ' + \ + ' AND hg.hostid=h.hostid ' + \ + ' AND t.triggerid=f.triggerid ' + \ + ' AND t.triggerid=e.triggerid ' + \ + ' AND e.eventid not in (select eventid from acknowledges) ' + \ + ' AND t.status=' + str(defines.TRIGGER_STATUS_ENABLED) + \ + ' AND i.status=' + str(defines.ITEM_STATUS_ACTIVE) + \ + ' AND h.status=' + str(defines.HOST_STATUS_MONITORED) + \ + ' AND t.value=' + str(defines.TRIGGER_VALUE_TRUE) + \ + ' ORDER BY t.lastchange DESC'; + # for i in session.execute(sql): print i + + query=[] + replace = re.compile(' {.*}') + for sql,ack in [(sql_ack,True), (sql_noack,False)]: + result = session.execute(sql) + for row in result: + try: + newrow = [ site_hn2lb[row[0].lower()] ] + [ r for r in row ] + except: + print site_hn2lb.keys() + newrow = [ "unknown" ] + [ r for r in row ] + + newrow[2] = replace.sub("", newrow[2]) # strip {.*} expressions + + # NOTE: filter count + filtercount['all'] += 1 + if not ack: # for unacknowledged + filtercount['active'] += 1 + if filter == 'active': + query.append(newrow) + else: + filtercount['acknowledged'] += 1 + if filter == 'acknowledged': + query.append(newrow) + + if filter != "acknowledged" and filter != "active": + query.append(newrow) + + return dict(query=query, fc=filtercount) diff --git a/web/MonitorWeb/monitorweb/static/css/style.css b/web/MonitorWeb/monitorweb/static/css/style.css index 072c484..60c902e 100644 --- a/web/MonitorWeb/monitorweb/static/css/style.css +++ b/web/MonitorWeb/monitorweb/static/css/style.css @@ -50,6 +50,13 @@ a.link, a, a.active { #site-good { background-color : darkseagreen; } #site-down { background-color: indianred; } +#severity-0 { background-color: #AADDAA; } +#severity-1 { background-color: #CCE2CC; } +#severity-2 { background-color: #EFEFCC; } +#severity-3 { background-color: #DDAAAA; } +#severity-4 { background-color: #FF8888; } +#severity-5 { background-color: #FF0000; } + /*#nps-table { background-color: lightgrey; }*/ /*#sub-table { background-color: lightgrey; }*/ /* td, th {padding:2px;border:none;} */ diff --git a/web/MonitorWeb/monitorweb/templates/master.kid b/web/MonitorWeb/monitorweb/templates/master.kid index ba39836..017b72a 100644 --- a/web/MonitorWeb/monitorweb/templates/master.kid +++ b/web/MonitorWeb/monitorweb/templates/master.kid @@ -15,8 +15,7 @@ text-align: right; } - +