def tag(tagid, begin_time, end_time, timestep, mode, utc, show): """Parse user friendly tag query and assemble userunfriendly wincc query""" query = tag_query_builder(tagid, begin_time, end_time, timestep, mode, utc) if show: print(query) return toc = tic() try: w = wincc(host_info.address, host_info.database) w.connect() w.execute(query) if w.rowcount(): print_tag_logging(w.fetchall()) # for rec in w.fetchall(): # print rec print("Fetched data in {time}.".format(time=round(toc(), 3))) except Exception as e: print(e) print(traceback.format_exc()) finally: w.close()
def tag2(tagid, begin_time, end_time, timestep, mode, utc, show, plot): """Parse user friendly tag query input and assemble wincc tag query""" if timestep and not end_time: end_time = datetime_to_str_without_ms(datetime.now()) query = tag_query_builder(tagid, begin_time, end_time, timestep, mode, utc) if show: print(query) return toc = tic() try: w = wincc(host_info.address, host_info.database) w.connect() w.execute(query) records = w.create_tag_records() print("Fetched data in {time}.".format(time=round(toc(), 3))) # print(tags) # tags.plot() for record in records: print(record) if plot: plot_tag_records(records) except Exception as e: print(e) print(traceback.format_exc()) finally: w.close()
def operator_messages(begin_time, end_time, text, utc, show): """Query db for operator messages.""" query = om_query_builder(eval_datetime(begin_time), eval_datetime(end_time), text, utc) if show: print(query) return try: toc = tic() w = wincc(host_info.address, host_info.database) w.connect() w.execute(query) w.print_operator_messages() print("Fetched data in {time}.".format(time=round(toc(), 3))) except WinCCException as e: print(e) print(traceback.format_exc()) finally: w.close()
def tag2(tagid, begin_time, end_time, timestep, mode, utc, show, plot, outfile, outfile_col_name, outfile_time_zone): """Parse user friendly tag query input and assemble wincc tag query""" if timestep and not end_time: end_time = datetime_to_str_without_ms(datetime.now()) query = tag_query_builder(tagid, begin_time, end_time, timestep, mode, utc) if show: print(query) return toc = tic() try: w = wincc(host_info.address, host_info.database) w.connect() w.execute(query) records = w.create_tag_records(utc) print("Fetched data in {time}.".format(time=round(toc(), 3))) if records: if (outfile != ''): with open(outfile, "w") as f: # print(records.to_csv().encode("UTF-8")) for rec in records: f.write( rec.to_csv(name=outfile_col_name.encode("UTF-8"), tz=outfile_time_zone)) else: for record in records: print(record) if plot: plot_tag_records(records) else: logging.warning("No data returned.") except Exception as e: print(e) print(traceback.format_exc()) finally: w.close()
def alarms(begin_time, end_time, text, utc, show, state, priority, priority2, report, report_hostname): """Read alarms from given host in given time.""" query = alarm_query_builder(eval_datetime(begin_time), eval_datetime(end_time), text, utc, state, priority, priority2) if show: print(query) return try: toc = tic() w = wincc(host_info.address, host_info.database) w.connect() w.execute(query) if report: alarms = w.create_alarm_record() if report_hostname: host_description = report_hostname else: host_description = host_info.description if not end_time: end_time = datetime_to_str_without_ms(datetime.now()) generate_alarms_report(alarms, begin_time, end_time, host_description, text) print(unicode(alarms)) else: w.print_alarms() print("Fetched data in {time}.".format(time=round(toc(), 3))) except WinCCException as e: print(e) print(traceback.format_exc()) finally: w.close()