def chkopts(opts): reg = re.compile("[^a-zA-Z0-9\./_:-]") if opts.host: if reg.search(opts.host): raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-t or --target', opts.host)) else: raise KssCommandOptException('ERROR: %s option is required.' % '-t or --target') if opts.iqn: if reg.search(opts.iqn): raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-i or --iqn', opts.iqn)) else: raise KssCommandOptException('ERROR: %s option is required.' % '-i or --iqn') if opts.auth: if not opts.auth == ISCSI_CONFIG_VALUE_AUTH_METHOD_CHAP and not opts.auth == ISCSI_CONFIG_VALUE_AUTH_METHOD_NONE: raise KssCommandOptException('ERROR: %s option is require %s or %s.' % ('-a or --auth', ISCSI_CONFIG_VALUE_AUTH_METHOD_CHAP, ISCSI_CONFIG_VALUE_AUTH_METHOD_NONE)) if opts.auth == ISCSI_CONFIG_VALUE_AUTH_METHOD_CHAP: if opts.user is None: raise KssCommandOptException('ERROR: %s option is required.' % '-u or --user') if opts.password is None and opts.password_file is None: raise KssCommandOptException('ERROR: %s option is required.' % '-p or --password or -w or --password-file') if opts.password_file is not None and not is_readable(opts.password_file): raise KssCommandOptException('ERROR: %s is not found.' % opts.password_file) else: raise KssCommandOptException('ERROR: %s option is required.' % '-a or --auth')
def read_iptables_config(self): config = {} res = [] if is_readable(self.iptables_conf_file): res = ConfigFile(self.iptables_conf_file).read() ret = 0 if len(res) == 0: cmd = [] cmd.append(self._iptables_save) (ret,res) = execute_command(cmd) table_regex = re.compile(r"""^\*(?P<table>[a-z]+)""") policy_regex = re.compile(r"""^:(?P<chain>\S+) (?P<target>\S+)""") rule_regex = re.compile(r"""^\-A (?P<rule>\S+)""") end_regex = re.compile(r"""^COMMIT$""") if ret == 0 and len(res) > 0: for aline in res: aline = aline.rstrip() aline = aline.replace(RH_USERCHAIN,FIREWALL_USERCHAIN) m = end_regex.match(aline) if m is not None: for chain, policy in policies.iteritems(): rule = self._make_rule_arr(rules[chain]) info = {"policy": policies[chain], "rule": rule} table_info[chain] = info config[table] = table_info continue m = table_regex.match(aline) if m is not None: table = m.group("table") table_info = {} policies = {} rules = {} else: m = policy_regex.match(aline) if m is not None: chain = m.group("chain") target = m.group("target") policies[chain] = target rules[chain] = [] else: m = rule_regex.match(aline) if m is not None: rule_chain = m.group("rule") rules[rule_chain].append(aline) #pp = pprint.PrettyPrinter(indent=4) #pp.pprint(config) return config
def is_df_file_exist(rrd_dir, dev): ret = True rrd_filepath = ("%s/df/df-%s.rrd" % (rrd_dir, dev), ) for filepath in rrd_filepath: if is_readable(filepath) is False: ret = False return ret
def is_libvirt_disk_file_exist(rrd_dir, dev): ret = True rrd_filepath = ("%s/libvirt/disk_octets-%s.rrd" % (rrd_dir, dev), "%s/libvirt/disk_ops-%s.rrd" % (rrd_dir, dev), ) for filepath in rrd_filepath: if is_readable(filepath) is False: ret = False return ret
def is_interface_file_exist(rrd_dir, dev): ret = True rrd_filepath = ("%s/interface/if_packets-%s.rrd" % (rrd_dir, dev), "%s/interface/if_octets-%s.rrd" % (rrd_dir, dev), "%s/interface/if_errors-%s.rrd" % (rrd_dir, dev), ) for filepath in rrd_filepath: if is_readable(filepath) is False: ret = False return ret
def is_disk_file_exist(rrd_dir, dev): ret = True rrd_filepath = ("%s/disk-%s/disk_merged.rrd" % (rrd_dir, dev), "%s/disk-%s/disk_octets.rrd" % (rrd_dir, dev), "%s/disk-%s/disk_ops.rrd" % (rrd_dir, dev), "%s/disk-%s/disk_time.rrd" % (rrd_dir, dev), ) for filepath in rrd_filepath: if is_readable(filepath) is False: ret = False return ret
def is_libvirt_cpu_file_exist(rrd_dir, dev): ret = True if dev == "total": rrd_filepath = ("%s/libvirt/virt_cpu_total.rrd" % (rrd_dir), ) else: rrd_filepath = ("%s/libvirt/virt_vcpu-%s.rrd" % (rrd_dir, dev), ) for filepath in rrd_filepath: if is_readable(filepath) is False: ret = False return ret
def is_cpu_file_exist(rrd_dir, dev): ret = True dev = str(dev) rrd_filepath = ("%s/cpu-%s/cpu-%s.rrd" % (rrd_dir, dev, "idle"), "%s/cpu-%s/cpu-%s.rrd" % (rrd_dir, dev, "interrupt"), "%s/cpu-%s/cpu-%s.rrd" % (rrd_dir, dev, "nice"), "%s/cpu-%s/cpu-%s.rrd" % (rrd_dir, dev, "user"), "%s/cpu-%s/cpu-%s.rrd" % (rrd_dir, dev, "wait"), "%s/cpu-%s/cpu-%s.rrd" % (rrd_dir, dev, "system"), "%s/cpu-%s/cpu-%s.rrd" % (rrd_dir, dev, "softirq"), "%s/cpu-%s/cpu-%s.rrd" % (rrd_dir, dev, "steal"), ) for filepath in rrd_filepath: if is_readable(filepath) is False: ret = False return ret
def create_load_graph(_, lang, graph_dir, rrd_dir, start, end, dev=None, type=None): graph_filename = "%s.png" % (generate_phrase(12,'abcdefghijklmnopqrstuvwxyz')) graph_filepath = "%s/%s" % (graph_dir, graph_filename) rrd_filepath = ("%s/load/load.rrd" % (rrd_dir), ) for filepath in rrd_filepath: if is_readable(filepath) is False: return "" legend_header_label = {"min":_('Min'), "max":_('Max'), "ave":_('Ave'), "last":_('Last'), } for key in legend_header_label.keys(): if re.search(u"[^a-zA-Z0-9]", legend_header_label[key]): legend_header_label[key] = "</tt>%s<tt>" % (legend_header_label[key].encode("utf-8")) else: legend_header_label[key] = "%s" % (legend_header_label[key].encode("utf-8")) legend_header = "<tt> %s %s %s %s</tt>" % (legend_header_label['min'], legend_header_label['max'], legend_header_label['ave'], legend_header_label['last'] ) title = _('Load Average') if re.search(u"[^a-zA-Z0-9_\-\. ]", title): title = "%s" % (title.encode("utf-8")) else: title = "<tt>%s</tt>" % (title.encode("utf-8")) # TRANSLATORS: # ロードアベレージのグラフの凡例 legend = {"1m":_('1m Average'), "5m":_('5m Average'), "15m":_('15m Average'), } for key in legend.keys(): if re.search(u"[^a-zA-Z0-9_\-\. ]", legend[key]): legend[key] = "</tt>%s <tt>" % (legend[key].encode("utf-8")) else: legend[key] = "%s" % (legend[key].encode("utf-8")) created_label = _('Graph created') if re.search(u"[^a-zA-Z0-9 ]", created_label): created_label = "</tt>%s<tt>" % (created_label.encode("utf-8")) else: created_label = "%s" % (created_label.encode("utf-8")) created_time = "%s" % (datetime.datetime.today().strftime(DEFAULT_LANGS[lang]['DATE_FORMAT'][1])) created_time = re.sub(r':', '\:', created_time) legend_footer = "<tt>%s \: %s</tt>" % (created_label, created_time) data = rrdtool.graph(graph_filepath, "--imgformat", "PNG", "--font", "TITLE:0:IPAexGothic", "--font", "LEGEND:0:IPAexGothic", "--pango-markup", "--width", "550", "--height", "350", "--full-size-mode", "--color", "BACK#FFFFFF", "--color", "CANVAS#FFFFFF", "--color", "SHADEA#FFFFFF", "--color", "SHADEB#FFFFFF", "--color", "GRID#DDDDDD", "--color", "MGRID#CCCCCC", "--color", "FONT#555555", "--color", "FRAME#FFFFFF", "--color", "ARROW#FFFFFF", "--title", title, "--vertical-label", _('System load').encode("utf-8"), "--start", start, "--end", end, "--units-exponent", "0", #"--legend-direction", "bottomup", "DEF:shortterm=%s:shortterm:AVERAGE" % (rrd_filepath[0]), "DEF:midterm=%s:midterm:AVERAGE" % (rrd_filepath[0]), "DEF:longterm=%s:longterm:AVERAGE" % (rrd_filepath[0]), "COMMENT:%s\\r" % legend_footer, "COMMENT:<tt>---------------------------------------------------------------------------</tt>\\n", "LINE:shortterm#E7EF00:<tt>%s </tt>" % (legend["1m"]), "GPRINT:shortterm:MIN:<tt>%8.2lf</tt>", "GPRINT:shortterm:MAX:<tt>%8.2lf</tt>", "GPRINT:shortterm:AVERAGE:<tt>%8.2lf</tt>", "GPRINT:shortterm:LAST:<tt>%8.2lf</tt>\\n", "LINE:midterm#B3EF00:<tt>%s </tt>" % (legend["5m"]), "GPRINT:midterm:MIN:<tt>%8.2lf</tt>", "GPRINT:midterm:MAX:<tt>%8.2lf</tt>", "GPRINT:midterm:AVERAGE:<tt>%8.2lf</tt>", "GPRINT:midterm:LAST:<tt>%8.2lf</tt>\\n", "LINE:longterm#80AA00:<tt>%s</tt>" % (legend["15m"]), "GPRINT:longterm:MIN:<tt>%8.2lf</tt>", "GPRINT:longterm:MAX:<tt>%8.2lf</tt>", "GPRINT:longterm:AVERAGE:<tt>%8.2lf</tt>", "GPRINT:longterm:LAST:<tt>%8.2lf</tt>\\n", "COMMENT:%s\\n" % (legend_header), "COMMENT: \\n", ) return graph_filepath
def create_uptime_graph(_, lang, graph_dir, rrd_dir, start, end, dev=None, type=None): graph_filename = "%s.png" % (generate_phrase(12,'abcdefghijklmnopqrstuvwxyz')) graph_filepath = "%s/%s" % (graph_dir, graph_filename) rrd_filepath = ("%s/uptime/uptime.rrd" % (rrd_dir), ) for filepath in rrd_filepath: if is_readable(filepath) is False: return "" legend_header_label = {"last":_('Last'), } for key in legend_header_label.keys(): if re.search(u"[^a-zA-Z0-9]", legend_header_label[key]): legend_header_label[key] = "</tt>%s<tt>" % (legend_header_label[key].encode("utf-8")) else: legend_header_label[key] = " %s" % (legend_header_label[key].encode("utf-8")) legend_header = "<tt> %s</tt>" % (legend_header_label['last']) # TRANSLATORS: # 起動時間のグラフの凡例 legend_label = {"uptime":_('uptime'), "day":_('days'), "hour":_('hours'), "minute":_('mins'), } for key in legend_label.keys(): if re.search(u"[^a-zA-Z0-9]", legend_label[key]): legend_label[key] = "</tt>%s<tt>" % (legend_label[key].encode("utf-8")) else: legend_label[key] = "%s" % (legend_label[key].encode("utf-8")) # TRANSLATORS: # 起動時間のグラフのタイトル title = _('Uptime') if re.search(u"[^a-zA-Z0-9_\-\.]", title): title = "%s" % (title.encode("utf-8")) else: title = "<tt>%s</tt>" % (title.encode("utf-8")) created_label = _('Graph created') if re.search(u"[^a-zA-Z0-9 ]", created_label): created_label = "</tt>%s<tt>" % (created_label.encode("utf-8")) else: created_label = "%s" % (created_label.encode("utf-8")) created_time = "%s" % (datetime.datetime.today().strftime(DEFAULT_LANGS[lang]['DATE_FORMAT'][1])) created_time = re.sub(r':', '\:', created_time) legend_footer = "<tt>%s \: %s</tt>" % (created_label, created_time) data = rrdtool.graph(graph_filepath, "--imgformat", "PNG", "--font", "TITLE:0:IPAexGothic", "--font", "LEGEND:0:IPAexGothic", "--pango-markup", "--width", "550", "--height", "350", "--full-size-mode", "--color", "BACK#FFFFFF", "--color", "CANVAS#FFFFFF", "--color", "SHADEA#FFFFFF", "--color", "SHADEB#FFFFFF", "--color", "GRID#DDDDDD", "--color", "MGRID#CCCCCC", "--color", "FONT#555555", "--color", "FRAME#FFFFFF", "--color", "ARROW#FFFFFF", "--title", title, # TRANSLATORS: # 起動時間のグラフの縦軸のラベル "--vertical-label", _('Days').encode("utf-8"), "--lower-limit", "0", "--rigid", "--start", start, "--end", end, "--alt-autoscale", #"--legend-direction", "bottomup", "DEF:uptime=%s:value:AVERAGE" % (rrd_filepath[0]), "CDEF:day=uptime,86400,/", "CDEF:hour=uptime,86400,%,3600,/", "CDEF:minute=uptime,3600,%,60,/", "COMMENT:%s\\r" % legend_footer, "COMMENT:<tt>---------------------------------------------------------------------------</tt>\\n", "AREA:day#80AA00:<tt>%s </tt>" % (legend_label["uptime"]), "GPRINT:day:LAST:<tt>%%6.0lf %s</tt>" % (legend_label["day"]), "GPRINT:hour:LAST:<tt>%%2.0lf %s</tt>" % (legend_label["hour"]), "GPRINT:minute:LAST:<tt>%%2.0lf %s</tt>\\n" % (legend_label["minute"]), "COMMENT:%s\\n" % (legend_header), "COMMENT: \\n", ) return graph_filepath
def create_cpu_graph(_, lang, graph_dir, rrd_dir, start, end, dev=0, type=None): cpu_number = str(dev) graph_filename = "%s.png" % (generate_phrase(12,'abcdefghijklmnopqrstuvwxyz')) graph_filepath = "%s/%s" % (graph_dir, graph_filename) rrd_filepath = ("%s/cpu-%s/cpu-%s.rrd" % (rrd_dir, cpu_number, "idle"), "%s/cpu-%s/cpu-%s.rrd" % (rrd_dir, cpu_number, "interrupt"), "%s/cpu-%s/cpu-%s.rrd" % (rrd_dir, cpu_number, "nice"), "%s/cpu-%s/cpu-%s.rrd" % (rrd_dir, cpu_number, "user"), "%s/cpu-%s/cpu-%s.rrd" % (rrd_dir, cpu_number, "wait"), "%s/cpu-%s/cpu-%s.rrd" % (rrd_dir, cpu_number, "system"), "%s/cpu-%s/cpu-%s.rrd" % (rrd_dir, cpu_number, "softirq"), "%s/cpu-%s/cpu-%s.rrd" % (rrd_dir, cpu_number, "steal"), ) for filename in rrd_filepath: if is_readable(filename) is False: return "" legend_header_label = {"min":_('Min'), "max":_('Max'), "ave":_('Ave'), "last":_('Last'), } for key in legend_header_label.keys(): if re.search(u"[^a-zA-Z0-9]", legend_header_label[key]): legend_header_label[key] = "</tt>%s<tt>" % (legend_header_label[key].encode("utf-8")) else: legend_header_label[key] = "%s" % (legend_header_label[key].encode("utf-8")) legend_header = "<tt> %s %s %s %s</tt>" % (legend_header_label['min'], legend_header_label['max'], legend_header_label['ave'], legend_header_label['last'] ) title = "<tt>CPU-%s</tt>" % (str(cpu_number)) created_label = _('Graph created') if re.search(u"[^a-zA-Z0-9 ]", created_label): created_label = "</tt>%s<tt>" % (created_label.encode("utf-8")) else: created_label = "%s" % (created_label.encode("utf-8")) created_time = "%s" % (datetime.datetime.today().strftime(DEFAULT_LANGS[lang]['DATE_FORMAT'][1])) created_time = re.sub(r':', '\:', created_time) legend_footer = "<tt>%s \: %s</tt>" % (created_label, created_time) data = rrdtool.graph(graph_filepath, "--imgformat", "PNG", "--font", "TITLE:0:IPAexGothic", "--font", "LEGEND:0:IPAexGothic", "--pango-markup", "--width", "550", "--height", "350", "--full-size-mode", "--color", "BACK#FFFFFF", "--color", "CANVAS#FFFFFF", "--color", "SHADEA#FFFFFF", "--color", "SHADEB#FFFFFF", "--color", "GRID#DDDDDD", "--color", "MGRID#CCCCCC", "--color", "FONT#555555", "--color", "FRAME#FFFFFF", "--color", "ARROW#FFFFFF", "--title", title, "--vertical-label", "jiffies", "--units-length", "2", "--upper-limit", "100", "--lower-limit", "0", "--rigid", "--start", start, "--end", end, #"--legend-direction", "bottomup", "DEF:idle=%s:value:AVERAGE" % (rrd_filepath[0]), "DEF:interrupt=%s:value:AVERAGE" % (rrd_filepath[1]), "DEF:nice=%s:value:AVERAGE" % (rrd_filepath[2]), "DEF:user=%s:value:AVERAGE" % (rrd_filepath[3]), "DEF:wait=%s:value:AVERAGE" % (rrd_filepath[4]), "DEF:system=%s:value:AVERAGE" % (rrd_filepath[5]), "DEF:softirq=%s:value:AVERAGE" % (rrd_filepath[6]), "DEF:steal=%s:value:AVERAGE" % (rrd_filepath[7]), "COMMENT:%s\\r" % legend_footer, "COMMENT:<tt>---------------------------------------------------------------------------</tt>\\n", # TRANSLATORS: # CPUのグラフの凡例 # 日本語にした場合は表示が崩れますが、後で直すのでそのままで大丈夫です "AREA:steal#FDFF6A:<tt>%s </tt>" % (_('Steal').encode("utf-8")), "GPRINT:steal:MIN:<tt>%8.2lf</tt>", "GPRINT:steal:MAX:<tt>%8.2lf</tt>", "GPRINT:steal:AVERAGE:<tt>%8.2lf</tt>", "GPRINT:steal:LAST:<tt>%8.2lf</tt>\\n", "STACK:interrupt#F7FF13:<tt>%s </tt>" % (_('Interrupt').encode("utf-8")), "GPRINT:interrupt:MIN:<tt>%8.2lf</tt>", "GPRINT:interrupt:MAX:<tt>%8.2lf</tt>", "GPRINT:interrupt:AVERAGE:<tt>%8.2lf</tt>", "GPRINT:interrupt:LAST:<tt>%8.2lf</tt>\\n", "STACK:softirq#E7EF00:<tt>%s </tt>" % (_('SoftIRQ').encode("utf-8")), "GPRINT:softirq:MIN:<tt>%8.2lf</tt>", "GPRINT:softirq:MAX:<tt>%8.2lf</tt>", "GPRINT:softirq:AVERAGE:<tt>%8.2lf</tt>", "GPRINT:softirq:LAST:<tt>%8.2lf</tt>\\n", "STACK:system#B5F100:<tt>%s </tt>" % (_('System').encode("utf-8")), "GPRINT:system:MIN:<tt>%8.2lf</tt>", "GPRINT:system:MAX:<tt>%8.2lf</tt>", "GPRINT:system:AVERAGE:<tt>%8.2lf</tt>", "GPRINT:system:LAST:<tt>%8.2lf</tt>\\n", "STACK:wait#B3EF00:<tt>%s </tt>" % (_('Wait - IO').encode("utf-8")), "GPRINT:wait:MIN:<tt>%8.2lf</tt>", "GPRINT:wait:MAX:<tt>%8.2lf</tt>", "GPRINT:wait:AVERAGE:<tt>%8.2lf</tt>", "GPRINT:wait:LAST:<tt>%8.2lf</tt>\\n", "STACK:user#95C700:<tt>%s </tt>" % (_('User').encode("utf-8")), "GPRINT:user:MIN:<tt>%8.2lf</tt>", "GPRINT:user:MAX:<tt>%8.2lf</tt>", "GPRINT:user:AVERAGE:<tt>%8.2lf</tt>", "GPRINT:user:LAST:<tt>%8.2lf</tt>\\n", "STACK:nice#80AA00:<tt>%s </tt>" % (_('Nice').encode("utf-8")), "GPRINT:nice:MIN:<tt>%8.2lf</tt>", "GPRINT:nice:MAX:<tt>%8.2lf</tt>", "GPRINT:nice:AVERAGE:<tt>%8.2lf</tt>", "GPRINT:nice:LAST:<tt>%8.2lf</tt>\\n", "STACK:idle#FFFFFF:<tt>%s </tt>" % (_('Idle').encode("utf-8")), "GPRINT:idle:MIN:<tt>%8.2lf</tt>", "GPRINT:idle:MAX:<tt>%8.2lf</tt>", "GPRINT:idle:AVERAGE:<tt>%8.2lf</tt>", "GPRINT:idle:LAST:<tt>%8.2lf</tt>\\n", "COMMENT:%s\\n" % (legend_header), "COMMENT: \\n", ) return graph_filepath
def process(self): (opts, args) = getopts() chkopts(opts) self.up_progress(10) original_parser = iscsidParser() new_parser = iscsidParser() dop = DictOp() dop.addconf("original", original_parser.read_conf()) dop.addconf("new", new_parser.read_conf()) self.up_progress(10) dop.cdp_set("new", ISCSI_CONFIG_KEY_AUTH_METHOD, opts.auth) if opts.auth == ISCSI_CONFIG_VALUE_AUTH_METHOD_CHAP: password = "" if opts.password is not None: password = opts.password elif opts.password_file is not None and is_readable(opts.password_file): try: fp = open(opts.password_file, "r") try: fcntl.lockf(fp.fileno(), fcntl.LOCK_SH) try: password = fp.readline().strip("\n") finally: fcntl.lockf(fp.fileno(), fcntl.LOCK_UN) self.up_progress(10) finally: fp.close() except: raise KssCommandException('Failed to read file. - target host=%s password_file=%s' \ % (opts.host,opts.password_file)) try: os.remove(opts.password_file) except: raise KssCommandException('Failed to remove file. - target host=%s password_file=%s' \ % (opts.host,opts.password_file)) dop.cdp_set("new", ISCSI_CONFIG_KEY_AUTH_METHOD, opts.auth) dop.cdp_set("new", ISCSI_CONFIG_KEY_AUTH_USER, opts.user) dop.cdp_set("new", ISCSI_CONFIG_KEY_AUTH_PASSWORD, password) else: dop.comment("new", ISCSI_CONFIG_KEY_AUTH_USER) dop.comment("new", ISCSI_CONFIG_KEY_AUTH_PASSWORD) self.up_progress(10) if opts.autostart: dop.cdp_set("new", ISCSI_CONFIG_KEY_SATRTUP, ISCSI_CONFIG_VALUE_SATRTUP_ON) else: dop.cdp_set("new", ISCSI_CONFIG_KEY_SATRTUP, ISCSI_CONFIG_VALUE_SATRTUP_OFF) new_parser.write_conf(dop.getconf("new")) self.up_progress(10) discovery_command_args = (ISCSI_CMD, ISCSI_CMD_OPTION_MODE, ISCSI_CMD_OPTION_MODE_DISCOVERY, ISCSI_CMD_OPTION_TYPE, ISCSI_CMD_OPTION_TYPE_SENDTARGETS, ISCSI_CMD_OPTION_PORTAL, opts.host ) (discovery_rc,discovery_res) = execute_command(discovery_command_args) self.up_progress(10) original_parser.write_conf(dop.getconf("original")) self.up_progress(10) if discovery_rc != 0: raise KssCommandException('Failed to add iSCSI. - host=%s message=%s' % (opts.host, discovery_res)) if discovery_res == []: raise KssCommandException('Failed to add iSCSI. - host=%s message=No exist permit iSCSI disk for target.' % (opts.host)) for node_line in discovery_res: if not node_line: continue try: node = iscsi_parse_node(node_line) except: self.logger.warn('Failed to parse iSCSI discovery command response. message="%s"' % (node_line)) continue self.logger.info("%s" % (iscsi_print_format_node(node))) print >>sys.stdout, _("%s") % (iscsi_print_format_node(node)) return True
def create_df_graph(_, lang, graph_dir, rrd_dir, start, end, dev, type=None): graph_filename = "%s.png" % (generate_phrase(12,'abcdefghijklmnopqrstuvwxyz')) graph_filepath = "%s/%s" % (graph_dir, graph_filename) rrd_filepath = ("%s/df/df-%s.rrd" % (rrd_dir, dev), ) for filepath in rrd_filepath: if is_readable(filepath) is False: return "" legend_header_label = {"min":_('Min'), "max":_('Max'), "ave":_('Ave'), "last":_('Last'), } for key in legend_header_label.keys(): if re.search(u"[^a-zA-Z0-9]", legend_header_label[key]): legend_header_label[key] = "</tt>%s<tt>" % (legend_header_label[key].encode("utf-8")) else: legend_header_label[key] = "%s" % (legend_header_label[key].encode("utf-8")) legend_header = "<tt> %s %s %s %s</tt>" % (legend_header_label['min'], legend_header_label['max'], legend_header_label['ave'], legend_header_label['last'] ) title = "<tt>%s</tt>" % (dev) legend = {"used" : _('Used'), "free" : _('Free'), } reg = re.compile(u"[^a-zA-Z0-9_\-\. ]") for key in legend.keys(): if key == "used": if reg.search(legend[key]): legend[key] = "</tt>%s<tt>" % (legend[key].encode("utf-8")) else: legend[key] = "%s" % (legend[key].encode("utf-8")) elif key == "free": if reg.search(legend[key]): legend[key] = "</tt>%s <tt>" % (legend[key].encode("utf-8")) else: legend[key] = "%s" % (legend[key].encode("utf-8")) else: legend[key] = "%s" % (legend[key].encode("utf-8")) created_label = _('Graph created') if re.search(u"[^a-zA-Z0-9 ]", created_label): created_label = "</tt>%s<tt>" % (created_label.encode("utf-8")) else: created_label = "%s" % (created_label.encode("utf-8")) created_time = "%s" % (datetime.datetime.today().strftime(DEFAULT_LANGS[lang]['DATE_FORMAT'][1])) created_time = re.sub(r':', '\:', created_time) legend_footer = "<tt>%s \: %s</tt>" % (created_label, created_time) data = rrdtool.graph(graph_filepath, "--imgformat", "PNG", "--font", "TITLE:0:IPAexGothic", "--font", "LEGEND:0:IPAexGothic", "--pango-markup", "--width", "550", "--height", "350", "--full-size-mode", "--color", "BACK#FFFFFF", "--color", "CANVAS#FFFFFF", "--color", "SHADEA#FFFFFF", "--color", "SHADEB#FFFFFF", "--color", "GRID#DDDDDD", "--color", "MGRID#CCCCCC", "--color", "FONT#555555", "--color", "FRAME#FFFFFF", "--color", "ARROW#FFFFFF", "--title", title, "--vertical-label", _('Bytes').encode("utf-8"), "--lower-limit", "0", "--rigid", "--start", start, "--end", end, #"--legend-direction", "bottomup", "DEF:used=%s:used:AVERAGE" % (rrd_filepath[0]), "DEF:free=%s:free:AVERAGE" % (rrd_filepath[0]), "COMMENT:%s\\r" % legend_footer, "COMMENT:<tt>---------------------------------------------------------------------------</tt>\\n", # TRANSLATORS: # ディスク容量のグラフの縦軸のラベル # 日本語にした場合は表示が崩れますが、後で直すのでそのままで大丈夫です "AREA:used#80AA00:<tt>%s </tt>" % (legend['used']), "GPRINT:used:MIN:<tt>%8.2lf%s</tt>", "GPRINT:used:MAX:<tt>%8.2lf%s</tt>", "GPRINT:used:AVERAGE:<tt>%8.2lf%s</tt>", "GPRINT:used:LAST:<tt>%8.2lf%s</tt>\\n", "STACK:free#FFFFFF:<tt>%s </tt>" % (legend['free']), "GPRINT:free:MIN:<tt>%8.2lf%s</tt>", "GPRINT:free:MAX:<tt>%8.2lf%s</tt>", "GPRINT:free:AVERAGE:<tt>%8.2lf%s</tt>", "GPRINT:free:LAST:<tt>%8.2lf%s</tt>\\n", "COMMENT:%s\\n" % (legend_header), "COMMENT: \\n", ) return graph_filepath
def create_load_graph(_, lang, graph_dir, rrd_dir, start, end, dev=None, type=None): graph_filename = "%s.png" % (generate_phrase(12, 'abcdefghijklmnopqrstuvwxyz')) graph_filepath = "%s/%s" % (graph_dir, graph_filename) rrd_filepath = ("%s/load/load.rrd" % (rrd_dir), ) for filepath in rrd_filepath: if is_readable(filepath) is False: return "" legend_header_label = { "min": _('Min'), "max": _('Max'), "ave": _('Ave'), "last": _('Last'), } for key in legend_header_label.keys(): if re.search(u"[^a-zA-Z0-9]", legend_header_label[key]): legend_header_label[key] = "</tt>%s<tt>" % ( legend_header_label[key].encode("utf-8")) else: legend_header_label[key] = "%s" % ( legend_header_label[key].encode("utf-8")) legend_header = "<tt> %s %s %s %s</tt>" % ( legend_header_label['min'], legend_header_label['max'], legend_header_label['ave'], legend_header_label['last']) title = _('Load Average') if re.search(u"[^a-zA-Z0-9_\-\. ]", title): title = "%s" % (title.encode("utf-8")) else: title = "<tt>%s</tt>" % (title.encode("utf-8")) # TRANSLATORS: # ロードアベレージのグラフの凡例 legend = { "1m": _('1m Average'), "5m": _('5m Average'), "15m": _('15m Average'), } for key in legend.keys(): if re.search(u"[^a-zA-Z0-9_\-\. ]", legend[key]): legend[key] = "</tt>%s <tt>" % (legend[key].encode("utf-8")) else: legend[key] = "%s" % (legend[key].encode("utf-8")) created_label = _('Graph created') if re.search(u"[^a-zA-Z0-9 ]", created_label): created_label = "</tt>%s<tt>" % (created_label.encode("utf-8")) else: created_label = "%s" % (created_label.encode("utf-8")) created_time = "%s" % (datetime.datetime.today().strftime( DEFAULT_LANGS[lang]['DATE_FORMAT'][1])) created_time = re.sub(r':', '\:', created_time) legend_footer = "<tt>%s \: %s</tt>" % (created_label, created_time) data = rrdtool.graph( graph_filepath, "--imgformat", "PNG", "--font", "TITLE:0:IPAexGothic", "--font", "LEGEND:0:IPAexGothic", "--pango-markup", "--width", "550", "--height", "350", "--full-size-mode", "--color", "BACK#FFFFFF", "--color", "CANVAS#FFFFFF", "--color", "SHADEA#FFFFFF", "--color", "SHADEB#FFFFFF", "--color", "GRID#DDDDDD", "--color", "MGRID#CCCCCC", "--color", "FONT#555555", "--color", "FRAME#FFFFFF", "--color", "ARROW#FFFFFF", "--title", title, "--vertical-label", _('System load').encode("utf-8"), "--start", start, "--end", end, "--units-exponent", "0", #"--legend-direction", "bottomup", "DEF:shortterm=%s:shortterm:AVERAGE" % (rrd_filepath[0]), "DEF:midterm=%s:midterm:AVERAGE" % (rrd_filepath[0]), "DEF:longterm=%s:longterm:AVERAGE" % (rrd_filepath[0]), "COMMENT:%s\\r" % legend_footer, "COMMENT:<tt>---------------------------------------------------------------------------</tt>\\n", "LINE:shortterm#E7EF00:<tt>%s </tt>" % (legend["1m"]), "GPRINT:shortterm:MIN:<tt>%8.2lf</tt>", "GPRINT:shortterm:MAX:<tt>%8.2lf</tt>", "GPRINT:shortterm:AVERAGE:<tt>%8.2lf</tt>", "GPRINT:shortterm:LAST:<tt>%8.2lf</tt>\\n", "LINE:midterm#B3EF00:<tt>%s </tt>" % (legend["5m"]), "GPRINT:midterm:MIN:<tt>%8.2lf</tt>", "GPRINT:midterm:MAX:<tt>%8.2lf</tt>", "GPRINT:midterm:AVERAGE:<tt>%8.2lf</tt>", "GPRINT:midterm:LAST:<tt>%8.2lf</tt>\\n", "LINE:longterm#80AA00:<tt>%s</tt>" % (legend["15m"]), "GPRINT:longterm:MIN:<tt>%8.2lf</tt>", "GPRINT:longterm:MAX:<tt>%8.2lf</tt>", "GPRINT:longterm:AVERAGE:<tt>%8.2lf</tt>", "GPRINT:longterm:LAST:<tt>%8.2lf</tt>\\n", "COMMENT:%s\\n" % (legend_header), "COMMENT: \\n", ) return graph_filepath
def create_interface_graph(_, lang, graph_dir, rrd_dir, start, end, dev, type): graph_filename = "%s.png" % (generate_phrase(12,'abcdefghijklmnopqrstuvwxyz')) graph_filepath = "%s/%s" % (graph_dir, graph_filename) rrd_filepath = ("%s/interface/if_%s-%s.rrd" % (rrd_dir, type, dev), ) # TRANSLATORS: # ネットワークのグラフのタイトル graph_title = { "packets":"%%s - %s" % (_('Packets').encode("utf-8")), "octets":"%%s - %s" % (_('Traffic').encode("utf-8")), "errors":"%%s - %s" % (_('Errors').encode("utf-8")), } # TRANSLATORS: # ネットワークのグラフの縦軸のラベル # packetsは1秒あたりのパケット数 # octetsは1秒あたりのバイト数 # errorsは1秒あたりのエラーパケット数 graph_label = { "packets":_("Packets / sec").encode("utf-8"), "octets":_("Octets / sec").encode("utf-8"), "errors":_("Packets / sec").encode("utf-8"), } for filepath in rrd_filepath: if is_readable(filepath) is False: return "" legend_header_label = {"min":_('Min'), "max":_('Max'), "ave":_('Ave'), "last":_('Last'), } for key in legend_header_label.keys(): if re.search(u"[^a-zA-Z0-9]", legend_header_label[key]): legend_header_label[key] = "</tt>%s<tt>" % (legend_header_label[key].encode("utf-8")) else: legend_header_label[key] = "%s" % (legend_header_label[key].encode("utf-8")) legend_header = "<tt> %s %s %s %s</tt>" % (legend_header_label['min'], legend_header_label['max'], legend_header_label['ave'], legend_header_label['last'] ) legend_label = {"rx":_('RX'), "tx":_('TX'), } for key in legend_label.keys(): if re.search(u"[^a-zA-Z0-9]", legend_label[key]): legend_label[key] = "</tt>%s<tt>" % (legend_label[key].encode("utf-8")) else: legend_label[key] = "%s" % (legend_label[key].encode("utf-8")) title = "<tt>%s</tt>" % (graph_title[type] % (dev)) created_label = _('Graph created') if re.search(u"[^a-zA-Z0-9 ]", created_label): created_label = "</tt>%s<tt>" % (created_label.encode("utf-8")) else: created_label = "%s" % (created_label.encode("utf-8")) created_time = "%s" % (datetime.datetime.today().strftime(DEFAULT_LANGS[lang]['DATE_FORMAT'][1])) created_time = re.sub(r':', '\:', created_time) legend_footer = "<tt>%s \: %s</tt>" % (created_label, created_time) data = rrdtool.graph(graph_filepath, "--imgformat", "PNG", "--font", "TITLE:0:IPAexGothic", "--font", "LEGEND:0:IPAexGothic", "--pango-markup", "--width", "550", "--height", "350", "--full-size-mode", "--color", "BACK#FFFFFF", "--color", "CANVAS#FFFFFF", "--color", "SHADEA#FFFFFF", "--color", "SHADEB#FFFFFF", "--color", "GRID#DDDDDD", "--color", "MGRID#CCCCCC", "--color", "FONT#555555", "--color", "FRAME#FFFFFF", "--color", "ARROW#FFFFFF", "--title", title, "--vertical-label", graph_label[type], "--start", start, "--end", end, #"--legend-direction", "bottomup", "DEF:rx=%s:rx:AVERAGE" % (rrd_filepath[0]), "DEF:tx=%s:tx:AVERAGE" % (rrd_filepath[0]), "COMMENT:%s\\r" % legend_footer, "COMMENT:<tt>---------------------------------------------------------------------------</tt>\\n", "AREA:rx#E7EF00:<tt>%s </tt>" % (legend_label["rx"]), "GPRINT:rx:MIN:<tt>%8.2lf%s</tt>", "GPRINT:rx:MAX:<tt>%8.2lf%s</tt>", "GPRINT:rx:AVERAGE:<tt>%8.2lf%s</tt>", "GPRINT:rx:LAST:<tt>%8.2lf%s</tt>\\n", "STACK:tx#80AA00:<tt>%s </tt>" % (legend_label["tx"]), "GPRINT:tx:MIN:<tt>%8.2lf%s</tt>", "GPRINT:tx:MAX:<tt>%8.2lf%s</tt>", "GPRINT:tx:AVERAGE:<tt>%8.2lf%s</tt>", "GPRINT:tx:LAST:<tt>%8.2lf%s</tt>\\n", "COMMENT:%s\\n" % (legend_header), "COMMENT: \\n", "LINE1:rx#E7EF00", "STACK:tx#80AA00", ) return graph_filepath
def create_libvirt_interface_graph(_, lang, graph_dir, rrd_dir, start, end, dev, type): graph_filename = "%s.png" % (generate_phrase(12,'abcdefghijklmnopqrstuvwxyz')) graph_filepath = "%s/%s" % (graph_dir, graph_filename) rrd_filepath = ("%s/libvirt/if_%s-%s.rrd" % (rrd_dir, type, dev), ) # TRANSLATORS: # 仮想マシンのグラフのネットワークグラフのタイトル graph_title = { "packets":"%%s - %s" % (_('Packets').encode("utf-8")), "octets":"%%s - %s" % (_('Traffic').encode("utf-8")), "errors":"%%s - %s" % (_('Errors').encode("utf-8")), "dropped":"%%s - %s" % (_('Dropped').encode("utf-8")), } # TRANSLATORS: # 仮想マシンのグラフのネットワークグラフの縦軸のラベル # packetsは1秒あたりのパケット数 # octetsは1秒あたりのバイト数 # errorsは1秒あたりのエラーパケット数 # droppedは1秒あたりのパケットドロップ数 graph_label = { "packets":_("Packets / sec").encode("utf-8"), "octets":_("Octets / sec").encode("utf-8"), "errors":_("Packets / sec").encode("utf-8"), "dropped":_("Packets / sec").encode("utf-8"), } for filepath in rrd_filepath: if is_readable(filepath) is False: return "" legend_header_label = {"min":_('Min'), "max":_('Max'), "ave":_('Ave'), "last":_('Last'), } for key in legend_header_label.keys(): if re.search(u"[^a-zA-Z0-9]", legend_header_label[key]): legend_header_label[key] = "</tt>%s<tt>" % (legend_header_label[key].encode("utf-8")) else: legend_header_label[key] = "%s" % (legend_header_label[key].encode("utf-8")) legend_header = "<tt> %s %s %s %s</tt>" % (legend_header_label['min'], legend_header_label['max'], legend_header_label['ave'], legend_header_label['last'] ) legend_label = {"rx":_('RX'), "tx":_('TX'), } for key in legend_label.keys(): if re.search(u"[^a-zA-Z0-9]", legend_label[key]): legend_label[key] = "</tt>%s<tt>" % (legend_label[key].encode("utf-8")) else: legend_label[key] = "%s" % (legend_label[key].encode("utf-8")) title = "<tt>%s - %s</tt>" % (rrd_dir.split('/')[-1], graph_title[type] % (dev)) created_label = _('Graph created') if re.search(u"[^a-zA-Z0-9 ]", created_label): created_label = "</tt>%s<tt>" % (created_label.encode("utf-8")) else: created_label = "%s" % (created_label.encode("utf-8")) created_time = "%s" % (datetime.datetime.today().strftime(DEFAULT_LANGS[lang]['DATE_FORMAT'][1])) created_time = re.sub(r':', '\:', created_time) legend_footer = "<tt>%s \: %s</tt>" % (created_label, created_time) data = rrdtool.graph(graph_filepath, GRAPH_COMMON_PARAM, "--title", title, "--vertical-label", graph_label[type], "--start", start, "--end", end, "--legend-direction", "bottomup", "DEF:rx=%s:rx:AVERAGE" % (rrd_filepath[0]), "DEF:tx=%s:tx:AVERAGE" % (rrd_filepath[0]), "COMMENT:%s\\r" % legend_footer, "COMMENT:<tt>---------------------------------------------------------------------------</tt>\\n", "AREA:rx#E7EF00:<tt>%s </tt>" % (legend_label["rx"]), "GPRINT:rx:MIN:<tt>%8.2lf%s</tt>", "GPRINT:rx:MAX:<tt>%8.2lf%s</tt>", "GPRINT:rx:AVERAGE:<tt>%8.2lf%s</tt>", "GPRINT:rx:LAST:<tt>%8.2lf%s</tt>\\n", "STACK:tx#80AA00:<tt>%s </tt>" % (legend_label["tx"]), "GPRINT:tx:MIN:<tt>%8.2lf%s</tt>", "GPRINT:tx:MAX:<tt>%8.2lf%s</tt>", "GPRINT:tx:AVERAGE:<tt>%8.2lf%s</tt>", "GPRINT:tx:LAST:<tt>%8.2lf%s</tt>\\n", "COMMENT:%s\\n" % (legend_header), "COMMENT: \\n", "LINE1:rx#E7EF00", "STACK:tx#80AA00", ) return graph_filepath
def create_libvirt_cpu_graph(_, lang, graph_dir, rrd_dir, start, end, dev, type): graph_filename = "%s.png" % (generate_phrase(12,'abcdefghijklmnopqrstuvwxyz')) graph_filepath = "%s/%s" % (graph_dir, graph_filename) if dev == "total": rrd_filepath = ("%s/libvirt/virt_cpu_total.rrd" % (rrd_dir), ) else: rrd_filepath = ("%s/libvirt/virt_vcpu-%s.rrd" % (rrd_dir, dev), ) for filepath in rrd_filepath: if is_readable(filepath) is False: return "" legend_header_label = {"min":_('Min'), "max":_('Max'), "ave":_('Ave'), "last":_('Last'), } for key in legend_header_label.keys(): if re.search(u"[^a-zA-Z0-9]", legend_header_label[key]): legend_header_label[key] = "</tt>%s<tt>" % (legend_header_label[key].encode("utf-8")) else: legend_header_label[key] = "%s" % (legend_header_label[key].encode("utf-8")) legend_header = "<tt> %s %s %s %s</tt>" % (legend_header_label['min'], legend_header_label['max'], legend_header_label['ave'], legend_header_label['last'] ) title = "<tt>%s - CPU-%s</tt>" % (rrd_dir.split('/')[-1], dev) created_label = _('Graph created') if re.search(u"[^a-zA-Z0-9 ]", created_label): created_label = "</tt>%s<tt>" % (created_label.encode("utf-8")) else: created_label = "%s" % (created_label.encode("utf-8")) created_time = "%s" % (datetime.datetime.today().strftime(DEFAULT_LANGS[lang]['DATE_FORMAT'][1])) created_time = re.sub(r':', '\:', created_time) legend_footer = "<tt>%s \: %s</tt>" % (created_label, created_time) data = rrdtool.graph(graph_filepath, "--imgformat", "PNG", "--font", "TITLE:0:IPAexGothic", "--font", "LEGEND:0:IPAexGothic", "--pango-markup", "--width", "550", "--height", "350", "--full-size-mode", "--color", "BACK#FFFFFF", "--color", "CANVAS#FFFFFF", "--color", "SHADEA#FFFFFF", "--color", "SHADEB#FFFFFF", "--color", "GRID#DDDDDD", "--color", "MGRID#CCCCCC", "--color", "FONT#555555", "--color", "FRAME#FFFFFF", "--color", "ARROW#FFFFFF", "--title", title, # TRANSLATORS: # 仮想マシンのグラフのCPUグラフの縦軸のラベル # 単位はCPU時間(秒)です "--vertical-label", _('Seconds').encode("utf-8"), "--units-exponent", "0", "--alt-y-grid", "--start", start, "--end", end, #"--legend-direction", "bottomup", "DEF:ns=%s:ns:AVERAGE" % (rrd_filepath[0]), "CDEF:s=ns,1000,1000,1000,*,*,/", "COMMENT:%s\\r" % legend_footer, "COMMENT:<tt>---------------------------------------------------------------------------</tt>\\n", # TRANSLATORS: # 仮想マシンのグラフのCPUグラフの凡例 "AREA:s#80AA00:<tt>%s </tt>" % (_('Seconds').encode("utf-8")), "GPRINT:s:MIN:<tt>%8.2lf</tt>", "GPRINT:s:MAX:<tt>%8.2lf</tt>", "GPRINT:s:AVERAGE:<tt>%8.2lf</tt>", "GPRINT:s:LAST:<tt>%8.2lf</tt>\\n", "COMMENT:%s\\n" % (legend_header), "COMMENT: \\n", "LINE1:s#80AA00", ) return graph_filepath
def create_disk_graph(_, lang, graph_dir, rrd_dir, start, end, dev, type): graph_filename = "%s.png" % (generate_phrase(12,'abcdefghijklmnopqrstuvwxyz')) graph_filepath = "%s/%s" % (graph_dir, graph_filename) rrd_filepath = ("%s/disk-%s/disk_%s.rrd" % (rrd_dir, dev, type), ) # TRANSLATORS: # ディスク性能のグラフの縦軸のラベル # /proc/diskstatsの値をとってきているらしいです # よく分からないので、公式HPの説明をコピペしておきます # # "merged" are the number of operations, that could be merged into other, already queued operations, i. e. one physical disk access served two or more logical operations. Of course, the higher that number, the better. # "time" is the average time an I/O-operation took to complete. Since this is a little messy to calculate take the actual values with a grain of salt. graph_label = { "merged":_("Merged Ops / sec").encode("utf-8"), "octets":_("Bytes / sec").encode("utf-8"), "ops":_("Ops / sec").encode("utf-8"), "time":_("Seconds / op").encode("utf-8"), } for filepath in rrd_filepath: if is_readable(filepath) is False: return "" legend_header_label = {"min":_('Min'), "max":_('Max'), "ave":_('Ave'), "last":_('Last'), } for key in legend_header_label.keys(): if re.search(u"[^a-zA-Z0-9]", legend_header_label[key]): legend_header_label[key] = "</tt>%s<tt>" % (legend_header_label[key].encode("utf-8")) else: legend_header_label[key] = "%s" % (legend_header_label[key].encode("utf-8")) legend_header = "<tt> %s %s %s %s</tt>" % (legend_header_label['min'], legend_header_label['max'], legend_header_label['ave'], legend_header_label['last'] ) legend_label = {"read":_('Read'), "write":_('Write'), } for key in legend_label.keys(): if re.search(u"[^a-zA-Z0-9]", legend_label[key]): legend_label[key] = "</tt>%s<tt>" % (legend_label[key].encode("utf-8")) else: if key == "read": legend_label[key] = "%s " % (legend_label[key].encode("utf-8")) else: legend_label[key] = "%s" % (legend_label[key].encode("utf-8")) title = "<tt>%s/disk_%s</tt>" % (dev,type) created_label = _('Graph created') if re.search(u"[^a-zA-Z0-9 ]", created_label): created_label = "</tt>%s<tt>" % (created_label.encode("utf-8")) else: created_label = "%s" % (created_label.encode("utf-8")) created_time = "%s" % (datetime.datetime.today().strftime(DEFAULT_LANGS[lang]['DATE_FORMAT'][1])) created_time = re.sub(r':', '\:', created_time) legend_footer = "<tt>%s \: %s</tt>" % (created_label, created_time) data = rrdtool.graph(graph_filepath, "--imgformat", "PNG", "--font", "TITLE:0:IPAexGothic", "--font", "LEGEND:0:IPAexGothic", "--pango-markup", "--width", "550", "--height", "350", "--full-size-mode", "--color", "BACK#FFFFFF", "--color", "CANVAS#FFFFFF", "--color", "SHADEA#FFFFFF", "--color", "SHADEB#FFFFFF", "--color", "GRID#DDDDDD", "--color", "MGRID#CCCCCC", "--color", "FONT#555555", "--color", "FRAME#FFFFFF", "--color", "ARROW#FFFFFF", "--title", title, "--vertical-label", graph_label[type], "--lower-limit", "0", "--rigid", "--start", start, "--end", end, #"--legend-direction", "bottomup", "DEF:read=%s:read:AVERAGE" % (rrd_filepath[0]), "DEF:write=%s:write:AVERAGE" % (rrd_filepath[0]), "COMMENT:%s\\r" % legend_footer, "COMMENT:<tt>---------------------------------------------------------------------------</tt>\\n", "AREA:read#E7EF00:<tt>%s </tt>" % legend_label["read"], "GPRINT:read:MIN:<tt>%8.2lf%s</tt>", "GPRINT:read:MAX:<tt>%8.2lf%s</tt>", "GPRINT:read:AVERAGE:<tt>%8.2lf%s</tt>", "GPRINT:read:LAST:<tt>%8.2lf%s</tt>\\n", "STACK:write#80AA00:<tt>%s </tt>" % legend_label["write"], "GPRINT:write:MIN:<tt>%8.2lf%s</tt>", "GPRINT:write:MAX:<tt>%8.2lf%s</tt>", "GPRINT:write:AVERAGE:<tt>%8.2lf%s</tt>", "GPRINT:write:LAST:<tt>%8.2lf%s</tt>\\n", "COMMENT:%s\\n" % (legend_header), "COMMENT: \\n", "LINE1:read#E7EF00", "STACK:write#80AA00", ) return graph_filepath
def create_libvirt_disk_graph(_, lang, graph_dir, rrd_dir, start, end, dev, type): graph_filename = "%s.png" % (generate_phrase(12,'abcdefghijklmnopqrstuvwxyz')) graph_filepath = "%s/%s" % (graph_dir, graph_filename) rrd_filepath = ("%s/libvirt/disk_%s-%s.rrd" % (rrd_dir, type, dev), ) graph_title = { "octets":"%s - %s", "ops":"%s - %s", } # TRANSLATORS: # 仮想マシンのグラフのディスクグラフの縦軸のラベル graph_label = { "octets":_('Bytes / sec').encode("utf-8"), "ops":_('Ops / sec').encode("utf-8"), } for filepath in rrd_filepath: if is_readable(filepath) is False: return "" legend_header_label = {"min":_('Min'), "max":_('Max'), "ave":_('Ave'), "last":_('Last'), } for key in legend_header_label.keys(): if re.search(u"[^a-zA-Z0-9]", legend_header_label[key]): legend_header_label[key] = "</tt>%s<tt>" % (legend_header_label[key].encode("utf-8")) else: legend_header_label[key] = "%s" % (legend_header_label[key].encode("utf-8")) legend_header = "<tt> %s %s %s %s</tt>" % (legend_header_label['min'], legend_header_label['max'], legend_header_label['ave'], legend_header_label['last'] ) legend_label = {"read":_('Read'), "write":_('Write'), } for key in legend_label.keys(): if re.search(u"[^a-zA-Z0-9]", legend_label[key]): legend_label[key] = "</tt>%s<tt>" % (legend_label[key].encode("utf-8")) else: if key == "read": legend_label[key] = "%s " % (legend_label[key].encode("utf-8")) else: legend_label[key] = "%s" % (legend_label[key].encode("utf-8")) title = "<tt>%s - %s</tt>" % (rrd_dir.split('/')[-1], graph_title[type] % (dev, type)) created_label = _('Graph created') if re.search(u"[^a-zA-Z0-9 ]", created_label): created_label = "</tt>%s<tt>" % (created_label.encode("utf-8")) else: created_label = "%s" % (created_label.encode("utf-8")) created_time = "%s" % (datetime.datetime.today().strftime(DEFAULT_LANGS[lang]['DATE_FORMAT'][1])) created_time = re.sub(r':', '\:', created_time) legend_footer = "<tt>%s \: %s</tt>" % (created_label, created_time) data = rrdtool.graph(graph_filepath, "--imgformat", "PNG", "--font", "TITLE:0:IPAexGothic", "--font", "LEGEND:0:IPAexGothic", "--pango-markup", "--width", "550", "--height", "350", "--full-size-mode", "--color", "BACK#FFFFFF", "--color", "CANVAS#FFFFFF", "--color", "SHADEA#FFFFFF", "--color", "SHADEB#FFFFFF", "--color", "GRID#DDDDDD", "--color", "MGRID#CCCCCC", "--color", "FONT#555555", "--color", "FRAME#FFFFFF", "--color", "ARROW#FFFFFF", "--title", title, "--vertical-label", graph_label[type], "--start", start, "--end", end, #"--legend-direction", "bottomup", "DEF:read=%s:read:AVERAGE" % (rrd_filepath[0]), "DEF:write=%s:write:AVERAGE" % (rrd_filepath[0]), "COMMENT:%s\\r" % legend_footer, "COMMENT:<tt>---------------------------------------------------------------------------</tt>\\n", "AREA:read#E7EF00:<tt>%s </tt>" % (legend_label["read"]), "GPRINT:read:MIN:<tt>%8.2lf%s</tt>", "GPRINT:read:MAX:<tt>%8.2lf%s</tt>", "GPRINT:read:AVERAGE:<tt>%8.2lf%s</tt>", "GPRINT:read:LAST:<tt>%8.2lf%s</tt>\\n", "STACK:write#80AA00:<tt>%s </tt>" % (legend_label["write"]), "GPRINT:write:MIN:<tt>%8.2lf%s</tt>", "GPRINT:write:MAX:<tt>%8.2lf%s</tt>", "GPRINT:write:AVERAGE:<tt>%8.2lf%s</tt>", "GPRINT:write:LAST:<tt>%8.2lf%s</tt>\\n", "COMMENT:%s\\n" % (legend_header), "COMMENT: \\n", "LINE1:read#E7EF00", "STACK:write#80AA00", ) return graph_filepath
def create_libvirt_disk_graph(_, lang, graph_dir, rrd_dir, start, end, dev, type): graph_filename = "%s.png" % (generate_phrase(12, 'abcdefghijklmnopqrstuvwxyz')) graph_filepath = "%s/%s" % (graph_dir, graph_filename) rrd_filepath = ("%s/libvirt/disk_%s-%s.rrd" % (rrd_dir, type, dev), ) graph_title = { "octets": "%s - %s", "ops": "%s - %s", } # TRANSLATORS: # 仮想マシンのグラフのディスクグラフの縦軸のラベル graph_label = { "octets": _('Bytes / sec').encode("utf-8"), "ops": _('Ops / sec').encode("utf-8"), } for filepath in rrd_filepath: if is_readable(filepath) is False: return "" legend_header_label = { "min": _('Min'), "max": _('Max'), "ave": _('Ave'), "last": _('Last'), } for key in legend_header_label.keys(): if re.search(u"[^a-zA-Z0-9]", legend_header_label[key]): legend_header_label[key] = "</tt>%s<tt>" % ( legend_header_label[key].encode("utf-8")) else: legend_header_label[key] = "%s" % ( legend_header_label[key].encode("utf-8")) legend_header = "<tt> %s %s %s %s</tt>" % ( legend_header_label['min'], legend_header_label['max'], legend_header_label['ave'], legend_header_label['last']) legend_label = { "read": _('Read'), "write": _('Write'), } for key in legend_label.keys(): if re.search(u"[^a-zA-Z0-9]", legend_label[key]): legend_label[key] = "</tt>%s<tt>" % ( legend_label[key].encode("utf-8")) else: if key == "read": legend_label[key] = "%s " % (legend_label[key].encode("utf-8")) else: legend_label[key] = "%s" % (legend_label[key].encode("utf-8")) title = "<tt>%s - %s</tt>" % (rrd_dir.split('/')[-1], graph_title[type] % (dev, type)) created_label = _('Graph created') if re.search(u"[^a-zA-Z0-9 ]", created_label): created_label = "</tt>%s<tt>" % (created_label.encode("utf-8")) else: created_label = "%s" % (created_label.encode("utf-8")) created_time = "%s" % (datetime.datetime.today().strftime( DEFAULT_LANGS[lang]['DATE_FORMAT'][1])) created_time = re.sub(r':', '\:', created_time) legend_footer = "<tt>%s \: %s</tt>" % (created_label, created_time) data = rrdtool.graph( graph_filepath, "--imgformat", "PNG", "--font", "TITLE:0:IPAexGothic", "--font", "LEGEND:0:IPAexGothic", "--pango-markup", "--width", "550", "--height", "350", "--full-size-mode", "--color", "BACK#FFFFFF", "--color", "CANVAS#FFFFFF", "--color", "SHADEA#FFFFFF", "--color", "SHADEB#FFFFFF", "--color", "GRID#DDDDDD", "--color", "MGRID#CCCCCC", "--color", "FONT#555555", "--color", "FRAME#FFFFFF", "--color", "ARROW#FFFFFF", "--title", title, "--vertical-label", graph_label[type], "--start", start, "--end", end, #"--legend-direction", "bottomup", "DEF:read=%s:read:AVERAGE" % (rrd_filepath[0]), "DEF:write=%s:write:AVERAGE" % (rrd_filepath[0]), "COMMENT:%s\\r" % legend_footer, "COMMENT:<tt>---------------------------------------------------------------------------</tt>\\n", "AREA:read#E7EF00:<tt>%s </tt>" % (legend_label["read"]), "GPRINT:read:MIN:<tt>%8.2lf%s</tt>", "GPRINT:read:MAX:<tt>%8.2lf%s</tt>", "GPRINT:read:AVERAGE:<tt>%8.2lf%s</tt>", "GPRINT:read:LAST:<tt>%8.2lf%s</tt>\\n", "STACK:write#80AA00:<tt>%s </tt>" % (legend_label["write"]), "GPRINT:write:MIN:<tt>%8.2lf%s</tt>", "GPRINT:write:MAX:<tt>%8.2lf%s</tt>", "GPRINT:write:AVERAGE:<tt>%8.2lf%s</tt>", "GPRINT:write:LAST:<tt>%8.2lf%s</tt>\\n", "COMMENT:%s\\n" % (legend_header), "COMMENT: \\n", "LINE1:read#E7EF00", "STACK:write#80AA00", ) return graph_filepath
def process(self): (opts, args) = getopts() chkopts(opts) self.up_progress(10) config_path = iscsi_get_config_path(opts.host, opts.iqn, opts.port, opts.tpgt) parser = iscsidParser() dop = DictOp() dop.addconf("new", parser.read_conf(config_path)) self.up_progress(10) dop.cdp_set("new", ISCSI_CONFIG_KEY_AUTH_METHOD, opts.auth) if opts.auth == ISCSI_CONFIG_VALUE_AUTH_METHOD_CHAP: password = "" if opts.password is not None: password = opts.password elif opts.password_file is not None and is_readable(opts.password_file): try: fp = open(opts.password_file, "r") try: fcntl.lockf(fp.fileno(), fcntl.LOCK_SH) try: password = fp.readline().strip("\n") finally: fcntl.lockf(fp.fileno(), fcntl.LOCK_UN) self.up_progress(10) finally: fp.close() except: raise KssCommandException('Failed to read file. - target host=%s password_file=%s' \ % (opts.host,opts.password_file)) try: os.remove(opts.password_file) except: raise KssCommandException('Failed to remove file. - target host=%s password_file=%s' \ % (opts.host,opts.password_file)) dop.cdp_set("new", ISCSI_CONFIG_KEY_AUTH_USER, opts.user) dop.cdp_set("new", ISCSI_CONFIG_KEY_AUTH_PASSWORD, password) else: dop.comment("new", ISCSI_CONFIG_KEY_AUTH_USER) dop.comment("new", ISCSI_CONFIG_KEY_AUTH_PASSWORD) self.up_progress(10) if opts.autostart: dop.cdp_set("new", ISCSI_CONFIG_KEY_SATRTUP, ISCSI_CONFIG_VALUE_SATRTUP_ON) else: dop.cdp_set("new", ISCSI_CONFIG_KEY_SATRTUP, ISCSI_CONFIG_VALUE_SATRTUP_OFF) self.up_progress(10) parser.write_conf(dop.getconf("new"), config_path) self.up_progress(30) self.logger.info("Updated iSCSI node. - host=%s iqn=%s" % (opts.host, opts.iqn)) print >>sys.stdout, _("Updated iSCSI node. - host=%s iqn=%s") % (opts.host, opts.iqn) return True