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 <<EOF > ${MONITOR_HTTP_CONF}
-NameVirtualHost *
-
-<VirtualHost *>
- 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
-
- #<Directory "${MONITORPATH}/web/MonitorWeb/monitorweb">
- # Options Indexes FollowSymLinks
- # AllowOverride None
- # Order allow,deny
- # Allow from all
- #</Directory>
- #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.
+<Location '/monitor/'>
+ #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/
+</Location>
-</VirtualHost>
EOF
}
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
-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
MESSAGE=$"Stopping Monitor"
dialog "$MESSAGE"
+ stop_tg_server
service zabbix_server stop
service zabbix_agentd stop
# TODO: is there anything to stop?
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
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(
"""This module contains functions called from console script entry points."""\r
\r
import sys\r
-from os import getcwd\r
+from os import getcwd, getpid\r
from os.path import dirname, exists, join\r
\r
import pkg_resources\r
except pkg_resources.DistributionNotFound:\r
raise ConfigurationError("Could not find default configuration.")\r
\r
+ if "prod" in configfile:\r
+ f = open("/var/run/monitorweb.pid", 'w')\r
+ f.write(str(getpid()))\r
+ f.close()\r
+\r
turbogears.update_config(configfile=configfile,\r
modulename="monitorweb.config")\r
\r
# 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 = []
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)
#site-good { background-color : darkseagreen; }\r
#site-down { background-color: indianred; }\r
\r
+#severity-0 { background-color: #AADDAA; }\r
+#severity-1 { background-color: #CCE2CC; }\r
+#severity-2 { background-color: #EFEFCC; }\r
+#severity-3 { background-color: #DDAAAA; }\r
+#severity-4 { background-color: #FF8888; }\r
+#severity-5 { background-color: #FF0000; }\r
+\r
/*#nps-table { background-color: lightgrey; }*/\r
/*#sub-table { background-color: lightgrey; }*/\r
/* td, th {padding:2px;border:none;} */\r
text-align: right;\r
}\r
</style>\r
- <link rel="stylesheet" type="text/css" media="screen" href="../static/css/style.css"\r
- py:attrs="href=tg.url('/static/css/style.css')"/>\r
+ <link rel="stylesheet" type="text/css" media="screen" href="${tg.url('static/css/style.css')}"/>\r
</head>\r
\r
<body py:match="item.tag=='{http://www.w3.org/1999/xhtml}body'" py:attrs="item.items()">\r