Example #1
0
def Main():
    try:
        "connection handles to site is optional in case polling to sites on SNMP/DyCOS server"
        for i in range(1, n + 1):
            S_handle = JetHandler()
            S_handle.OpenRequestResponseSession(device=globals()['S%s_IP' % i],
                                                port=PORT,
                                                user=USER,
                                                password=PASSWORD,
                                                client_id=CLIENT_ID)
            S_mgmt = S_handle.GetManagementService()
            globals()['mgmt_S%s' % i] = S_mgmt

        "MX router connection and JET service handles"
        for i in range(1, n - 1):
            R_handle = JetHandler()
            R_handle.OpenRequestResponseSession(device=globals()['R%s_IP' % i],
                                                port=PORT,
                                                user=USER,
                                                password=PASSWORD,
                                                client_id=CLIENT_ID)
            R_fw = R_handle.GetFirewallService()
            R_mgmt = R_handle.GetManagementService()
            globals()['mgmt_R%s' % i] = R_mgmt
            globals()['fw_R%s' % i] = R_fw

        Initial_Cos_Configs()
        Get_Site_Latest_Data()

    except KeyboardInterrupt:
        pass
    except Exception as tx:
        print '%s' % (tx.message)
    return
Example #2
0
def mail(message):
    smtpObj = smtplib.SMTP('smtp.juniper.net')
    smtpObj.sendmail(sender, receivers, message)
    print "Successfully sent email"

try:
    # Create a client handler for connecting to server
    client = JetHandler()

    # Open session with Thrift Servers
    client.OpenRequestResponseSession(device=R1, connect_timeout=300000, user=APP_USER, password=APP_PASSWORD, client_id= "1211111")
    print "\nEstablished connection with the", R1

    # Create a service handlers
    R1_route_handle = client.GetRouteService()
    R1_mgmt_handle = client.GetManagementService()

    # Create a event handlers to MQTT server
    evHandle = client.OpenNotificationSession(device=R1)

    # Subscribe for syslog events
    syslog = evHandle.CreateSyslogTopic("SNMPD_RMON_EVENTLOG")
    print "Subscribing to Syslog RMON notifications"
    evHandle.Subscribe(syslog, on_message)

    while 1:
        1 + 1

except Exception as tx:
    print '%s' % tx.message