CHECK_LENGTH, CHECK_MIN, CHECK_MAX
from karesansui.db.access.watch import \
- findbyall, findby1, findbyand, \
+ findbyall as w_findbyall, findby1 as w_findby1, \
+ findby1name as w_findby1name, findbyand as w_findbyand, \
new as w_new, save as w_save
-from karesansui.lib.utils import is_param, create_plugin_selector
+from karesansui.db.access.watch1mailtemplate import \
+ new as w1m_new, save as w1m_save
+
+from karesansui.db.access.mailtemplate import \
+ findbyall as m_findbyall, findby1name as m_findby1name
+
+from karesansui.lib.utils import is_param, create_plugin_selector, \
+ create_value_selector
from karesansui.lib.const import WATCH_LIST_RANGE, \
COLLECTD_PLUGIN_CPU, COLLECTD_PLUGIN_DF, \
COLLECTD_MEMORY_TYPE_INSTANCE, COLLECTD_DF_DS, COLLECTD_DISK_TYPE, \
COLLECTD_DISK_DS, COLLECTD_INTERFACE_TYPE, COLLECTD_INTERFACE_DS, \
COLLECTD_CPU_TYPE, COLLECTD_MEMORY_TYPE, COLLECTD_DF_TYPE, \
- COLLECTD_UPTIME_TYPE, COLLECTD_LIBVIRT_TYPE
+ COLLECTD_UPTIME_TYPE, COLLECTD_LIBVIRT_TYPE, \
+ COLLECTD_CPU_DS, COLLECTD_MEMORY_DS, COLLECTD_UPTIME_DS, \
+ VALUE_BOUNDS_UPPER, VALUE_BOUNDS_LOWER
+
def validates_watch(obj):
check = True
self.view.disk_ds = COLLECTD_DISK_DS
self.view.interface_type = COLLECTD_INTERFACE_TYPE
self.view.interface_ds = COLLECTD_INTERFACE_DS
+ self.view.value_bounds_upper = VALUE_BOUNDS_UPPER
+ self.view.value_bounds_lower = VALUE_BOUNDS_LOWER
return True
-
if not validates_query(self):
self.logger.debug("Show watch is failed, "
"Invalid query value "
return web.badrequest(self.view.alert)
if is_param(self.input, 'q') is True:
- watchs = findbyand(self.orm, self.input.q)
+ watchs = w_findbyand(self.orm, self.input.q)
if not watchs:
self.logger.debug("Show watch is failed, "
"Could not find watch "
return web.nocontent()
self.view.search_value = self.input.q
else:
- watchs = findbyall(self.orm)
+ watchs = w_findbyall(self.orm)
self.view.search_value = ""
if not watchs:
self.logger.debug("Show watch is failed, "
plugin_instance = None
type = None
type_instance = None
+ plugin_ds = None
if plugin == COLLECTD_PLUGIN_CPU:
#cpu method
type_instance = self.input.cpu_status
type = COLLECTD_CPU_TYPE
+ plugin_ds = COLLECTD_CPU_DS
elif plugin == COLLECTD_PLUGIN_MEMORY:
#memory method
type_instance = self.input.memory_status
type = COLLECTD_MEMORY_TYPE
+ plugin_ds = COLLECTD_MEMORY_DS
elif plugin == COLLECTD_PLUGIN_DF:
#df method
type = COLLECTD_DF_TYPE
+ plugin_ds = self.input.df_disk_status
elif plugin == COLLECTD_PLUGIN_DISK:
#disk method
type = self.input.disk_disk_status
+ plugin_ds = self.input.disk_value_type
elif plugin == COLLECTD_PLUGIN_INTERFACE:
#interface method
type = self.input.network_status
+ plugin_ds = self.input.network_direction
elif plugin == COLLECTD_PLUGIN_LIBVIRT:
#libvirt method
if self.input.libvirt_target == "cpu":
type = COLLECTD_LIBVIRT_TYPE['CPU_TOTAL']
+ plugin_ds = COLLECTD_CPU_DS
elif self.input.libvirt_target == "disk":
type = "disk_" + self.input.libvirt_disk_status
+ plugin_ds = self.input.libvirt_disk_value_type
elif self.input.libvirt_target == "network":
type = "if_" + self.input.libvirt_network_status
+ plugin_ds = self.input.libvirt_network_direction
elif plugin == COLLECTD_PLUGIN_UPTIME:
#uptime method
type = COLLECTD_UPTIME_TYPE
+ plugin_ds = COLLECTD_UPTIME_DS
plugin_selector = create_plugin_selector(plugin_instance, type, type_instance)
- # value_selectorの作成
-
-
- # DBに登録
_watch = w_new(created_user=self.me,
modified_user=self.me,
plugin_selector=plugin_selector,
karesansui_version="1.2",
collectd_version="4.9",
- is_deleted=False
+ is_deleted=False,
)
w_save(self.orm, _watch)
+ # value_selectorの作成
+
+ value_count = int(self.input.value_count)
+ count = 1
+ while(count <= value_count):
+ value = eval("self.input.threshold_value_" + str(count))
+ value_bounds = eval("self.input.value_bounds_" + str(count))
+ shell = eval("self.input.shell_script_" + str(count))
+ mailtemplate_name = eval("self.input.mail_template_" + str(count))
+ if mailtemplate_name == "no":
+ mailtemplate = None
+ else:
+ mailtemplate = m_findby1name(self.orm, mailtemplate_name).id
+
+ value_selector = create_value_selector(plugin_ds, value, value_bounds)
+
+ _w1m = w1m_new(created_user=self.me,
+ modified_user=self.me,
+ watch=_watch,
+ mailtemplate=mailtemplate,
+ value_selector=value_selector,
+ shell=shell,
+ )
+
+ w1m_save(self.orm, _w1m)
+ count += 1
+
+
return web.created(None)
urls = (
from karesansui.lib.pager import Pager, validates_page
from karesansui.lib.search import validates_query
from karesansui.lib.const import \
- TAG_LIST_RANGE, TAG_MIN_LENGTH, TAG_MAX_LENGTH, \
ID_MIN_LENGTH, ID_MAX_LENGTH
from karesansui.db.access.watch import \
- findby1
+ findby1, logical_delete
from karesansui.lib.checker import Checker, \
CHECK_EMPTY, CHECK_VALID, \
check = True
return check
+def validates_param_id(obj, watch_id):
+ checker = Checker()
+ check = True
+
+ _ = obj._
+ checker.errors = []
+
+ check = checker.check_number(
+ _('Watch ID'),
+ watch_id,
+ CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX,
+ min = ID_MIN_LENGTH,
+ max = ID_MAX_LENGTH,
+ ) and check
+
+ obj.view.alert = checker.errors
+ return check
+
+
class WatchBy1(Rest):
@auth
@auth
def _DELETE(self, *param, **params):
- return web.seeother("/%s.%s" % ("tag", "part"))
+ watch_id = param[0]
+
+ if not validates_param_id(self, watch_id):
+ self.logger.debug("Update watch is failed, Invalid param value.")
+ return web.notfound(self.view.alert)
+
+
+ watch = findby1(self.orm, watch_id)
+ if not watch:
+ self.logger.debug("Delete watch is failed, "
+ "Did not exist watch - id=%s" % watch_id)
+ return web.notfound()
+
+ logical_delete(self.orm, watch)
+ return web.seeother("/%s.%s" % ("watch", "part"))
+
urls = (
'/watch/(\d+)/?(\.part)$', WatchBy1,
<div>------------------------------------------------------</div>
<br style="clear: both;"/>
+ <input type="hidden" name="value_count" id="value_count" value="1" />
<div id="value-section">
- <div class="grayout-param">${_('Threshold Value')}<span id="watch_threshold_value_help"></span></div>
- <div class="grayout-value grayout-form">
- <input type="text" name="threshold_value_1" id="threshold_value_1" />
- </div>
- <div class="grayout-param">${_('Shell Script')}<span id="watch_shell_script_help"></span></div>
- <div class="grayout-value grayout-form">
- <textarea name="shell_script_1" id="shell_script_1" />
- </div>
- <div class="grayout-param">${_('Mail Template')}<span id="watch_mail_template_help"></span></div>
- <div class="grayout-value grayout-form">
- <select name="mail_template_1" id="mail_template_1">
- <option id="template_0" value="template_0">${_('No Send Mail')}</option>
- <option id="template_1" value="template_1">${_('Template 1')}</option>
- </select>
+ <div id="value-section_1">
+ <div class="grayout-param">${_('Threshold Value')}<span id="watch_threshold_value_help"></span></div>
+ <div class="grayout-value grayout-form">
+ <input type="text" name="threshold_value_1" id="threshold_value_1" />
+ </div>
+ <div class="grayout-param">${_('Value Bounds')}<span id="watch_value_bounds_help"></span></div>
+ <div class="grayout-value grayout-form">
+ <input type="radio" name="value_bounds_1" value="${value_bounds_lower}">${_('Lower')}
+ <input type="radio" name="value_bounds_1" value="${value_bounds_upper}" checked>${_('Upper')}
+ </div>
+ <div class="grayout-param">${_('Shell Script')}<span id="watch_shell_script_help"></span></div>
+ <div class="grayout-value grayout-form">
+ <textarea name="shell_script_1" id="shell_script_1" />
+ </div>
+ <div class="grayout-param">${_('Mail Template')}<span id="watch_mail_template_help"></span></div>
+ <div class="grayout-value grayout-form">
+ <select name="mail_template_1" id="mail_template_1">
+ <option id="mail_template_0" value="no">${_('No Send Mail')}</option>
+ <option id="mail_template_1" value="template_1">${_('Template 1')}</option>
+ </select>
+ </div>
</div>
</div>