def __init__(self): self.logger = get_logger('collector') self.device_info = None self.job_order_queue = None self.scheduler = BackgroundScheduler(timezone="Asia/Seoul") self.scheduler.start() self.templates = dict() self.data = dict() self.data['__last_fetch'] = dict() self.queue = deque(maxlen=60)
def __init__(self, host, port, community_read='public', community_write='private', version=2): self.host = host self.port = port self.logger = get_logger('snmp-handler') self.address = (host, port) self.community_read = community_read self.community_write = community_write self.version = version
import flask import operator from flask import request, abort, make_response from flask import jsonify, redirect, url_for from functools import wraps from restful_snmp_api.modules.api import CustomBlueprint from restful_snmp_api.utils.logger import get_logger from restful_snmp_api.manager import (ExceptionResponse, ExceptionScheduleReduplicated, NotFound) logger = get_logger('api-v1') bp = CustomBlueprint('api', __name__) ############################################################################### def custom_error(message, status_code): msg = dict(message=message) return make_response(jsonify(msg), status_code) ############################################################################### def result(f): @wraps(f) def func(*args, **kwargs): try: r = f(*args, **kwargs) return jsonify(r) except ExceptionScheduleReduplicated as e: return custom_error(str(e), 400)
import datetime import functools import shlex from restful_snmp_api.snmp_handler.handler import SnmpHandler from restful_snmp_api.utils.logger import get_logger from restful_snmp_api.snmp_handler.arugment_parser import \ argument_parser logger = get_logger('snmp-handler') ############################################################################### class SnmpClient(SnmpHandler): def __init__(self, host, port, community_read='public', community_write='private', version=2): SnmpHandler.__init__(self, host, port, community_read, community_write, version) # ========================================================================= def __enter__(self): return self # ========================================================================= def __exit__(self, exc_type, exc_val, exc_tb): if exc_tb: import traceback
from requests import Response from flask import request from flask import jsonify from flask import render_template from restful_snmp_api.modules.api import CustomBlueprint from restful_snmp_api.modules.api.v1.api import schedules as api_schedules from restful_snmp_api.utils.logger import get_logger logger = get_logger('module-schedules') bp = CustomBlueprint('schedules', __name__, template_folder='templates', static_folder='static', static_url_path='assets') @bp.route('/', methods=('GET', 'POST')) def schedules(): if request.method == 'GET': logger.info('get called') collector = bp.gv['collector'] a: Response = api_schedules() print(a.status_code) schedule_list = collector.get_schedule_jobs() return render_template('schedules/view.html', schedule_list=schedule_list)
import argparse import yaml import pathlib from restful_snmp_api.app import app from restful_snmp_api.app import collector from restful_snmp_api.utils.logger import get_logger logger = get_logger(__package__) MIB_DIRECTORY = pathlib.Path.home() / pathlib.Path('.snmp/mibs') def argument_parser(): parser = argparse.ArgumentParser('restful-modbus-api') parser.add_argument('-a', '--address', default='localhost', help='host address') parser.add_argument('-p', '--port', type=int, default=5000, help='port') parser.add_argument('-d', '--debug', action='store_true') parser.add_argument('-t', '--template_file', type=str, action='append') parser.add_argument('-m', '--mib_file', type=str, action='append') return parser def main(): parser = argument_parser() argspec = parser.parse_args() if argspec.template_file: for t in argspec.template_file: with open(t, 'r') as f: