from cim_client import CIMClient
from snmp_client import SNMPClient
from flask import Flask, redirect, render_template, url_for

# Initiate Flask
app = Flask(__name__)

# Frontpage method redirecting to CIM dashboard
@app.route("/")
def index():
    return redirect(url_for('cim_dashboard'))

# CIM dashboard method
@app.route("/cim")
def cim_dashboard():
    client = CIMClient()
    try:
        os_info = client.get_os_info()
    except:
        os_info = 'not availible'
    try:
        ip_interfaces = client.get_ip_interfaces()
    except:
        ip_interfaces = []

    return render_template('cim.html',
        os_info=os_info, ip_interfaces=ip_interfaces)

# SNMP dashboard method
@app.route("/snmp")
def snmp_dashboard():
    snmp = SNMPClient()

    try:
        os_info = snmp.getOs()
    except:
        os_info = "Host not availible"
    
    try:
        ip_interfaces = snmp.getNetwork()
    except:
        ip_interfaces = [] 
    
    return render_template('snmp.html',
        os_info=os_info, ip_interfaces=ip_interfaces)#, url_for=url_for())

# Run the server
if __name__ == "__main__":
    app.run()
