forked from Nirubu/nexus5000
-
Notifications
You must be signed in to change notification settings - Fork 0
/
onep-create_syslog.py
75 lines (68 loc) · 2.54 KB
/
onep-create_syslog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#! /usr/bin/env python
# *------------------------------------------------------------------
# * onep-create_syslog.py
# *
# * Simple script to generate a syslog messsage
# *
# * Cisco ONE-P Python SDK
# *
# * Copyright (c) 2011-2014 by Cisco Systems, Inc.
# * All rights reserved.
# *------------------------------------------------------------------
# *
#
# Must have a Cisco device capable of communicating with ONE-P APIs.
# Network Element must also have onep configured with the socket
# transport and have the correct onep services activated.
# Depending on OnePK SDK release, supported tranport type could be
# TIPC and TLS. Check on device using the following CLIs:
# conf t --> onep --> transport type ?
#
# A network interface must be configured with a valid IP address and
# pingable.
#
# To use this script you should:
# 1) Copy the file to a server with OpePK SDK
# 2) setup the variables in the section below
# 3) run the script: python onep-create_syslog.py
#
from onep.element.NetworkElement import NetworkElement
from onep.element.SessionConfig import SessionConfig
from onep.interfaces.InterfaceStatistics import InterfaceStatistics
from onep.interfaces.InterfaceFilter import *
#####################################################################
# Variables to be changed
#
# transport- Transport type: either TIPC or TLS
# check tranport types supported on your image by
# conf t --> onep --> transport type ?
# cert - certificate to be used for authentication in cse of TLS
# transport
# appName - OnePK application Name
# switchIP - management Switch IP address
# user - switch userID
pswd = "<pswd>"
logMsg = "syslog generated by onePK"
#####################################################################
#
# Set up session connection configuration and connect to the switch
#
ne = NetworkElement(switchIP, appName)
if transport == 'TLS':
session_config = SessionConfig(SessionConfig.SessionTransportMode.TLS)
session_config.ca_certs = cert
ne.connect(user, pswd, session_config)
elif transport == 'TIPC':
session_config = SessionConfig(SessionConfig.SessionTransportMode.TIPC)
ne.connect(user, pswd)
else:
print "Please set-up a valid transport type: TIPC or TLS"
exit(0)
#
# Create the syslog messange and disconnect from the device
#
print "Generating Syslog message."
ne.create_syslog_message(ne.OnepSyslogSeverity.ONEP_SYSLOG_CRITICAL, logMsg);
print "Check on switch logs using \"sh log log duration 00:05:00\" cli"
print "Disconnecting from device: ", switchIP
ne.disconnect()