Class: Cisco::SyslogSettings

Inherits:
NodeUtil show all
Defined in:
lib/cisco_node_utils/syslog_settings.rb

Overview

SyslogSettings - node utility class for Syslog Settings configuration management

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NodeUtil

client, #client, config_get, #config_get, #config_get_default, config_get_default, config_set, #config_set, #get, #ios_xr?, #nexus?, #node, node, platform, #platform, supports?, #supports?

Constructor Details

#initialize(name) ⇒ SyslogSettings

Returns a new instance of SyslogSettings.



28
29
30
31
32
33
34
# File 'lib/cisco_node_utils/syslog_settings.rb', line 28

def initialize(name)
  fail TypeError unless name.is_a?(String)
  fail ArgumentError,
       "This provider only accepts an id of 'default'" \
       unless name.eql?('default')
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



26
27
28
# File 'lib/cisco_node_utils/syslog_settings.rb', line 26

def name
  @name
end

Class Method Details

.syslogsettingsObject



36
37
38
39
40
# File 'lib/cisco_node_utils/syslog_settings.rb', line 36

def self.syslogsettings
  hash = {}
  hash['default'] = SyslogSettings.new('default')
  hash
end

Instance Method Details

#==(other) ⇒ Object



42
43
44
# File 'lib/cisco_node_utils/syslog_settings.rb', line 42

def ==(other)
  name == other.name
end

#consoleObject



50
51
52
53
54
55
56
# File 'lib/cisco_node_utils/syslog_settings.rb', line 50

def console
  console = config_get('syslog_settings', 'console')
  if console.is_a?(Array)
    console = console[0] == 'no' ? 'unset' : console[1]
  end
  console
end

#console=(severity) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/cisco_node_utils/syslog_settings.rb', line 58

def console=(severity)
  if severity
    config_set(
      'syslog_settings', 'console',
      state: '', severity: severity)
  else
    config_set(
      'syslog_settings', 'console',
      state: 'no', severity: '')
  end
end

#default_consoleObject



46
47
48
# File 'lib/cisco_node_utils/syslog_settings.rb', line 46

def default_console
  config_get_default('syslog_settings', 'console')
end

#default_monitorObject



70
71
72
# File 'lib/cisco_node_utils/syslog_settings.rb', line 70

def default_monitor
  config_get_default('syslog_settings', 'monitor')
end

#default_source_interfaceObject



94
95
96
# File 'lib/cisco_node_utils/syslog_settings.rb', line 94

def default_source_interface
  config_get_default('syslog_settings', 'source_interface')
end

#logfile_nameObject



155
156
157
158
159
160
161
# File 'lib/cisco_node_utils/syslog_settings.rb', line 155

def logfile_name
  logfile_name = config_get('syslog_settings', 'logfile_name')
  if logfile_name.is_a?(Array)
    logfile_name = (logfile_name[0] == 'no') ? 'unset' : logfile_name[1]
  end
  logfile_name
end

#logfile_name=(logname, severity, size) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
# File 'lib/cisco_node_utils/syslog_settings.rb', line 143

def logfile_name=(logname, severity, size)
  if logname
    config_set(
      'syslog_settings', 'logfile_name',
      state: '', logname: logname, severity: severity, size: size)
  else
    config_set(
      'syslog_settings', 'logfile_name',
      state: 'no', logname: logname, severity: severity, size: size)
  end
end

#logfile_severity_levelObject



130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/cisco_node_utils/syslog_settings.rb', line 130

def logfile_severity_level
  logfile_severity_level =
      config_get('syslog_settings', 'logfile_severity_level')
  if logfile_severity_level.is_a?(Array)
    if logfile_severity_level[0] == 'no'
      logfile_severity_level = nil
    else
      logfile_severity_level = logfile_severity_level[1]
    end
  end
  logfile_severity_level
end

#logfile_sizeObject



163
164
165
166
167
168
169
# File 'lib/cisco_node_utils/syslog_settings.rb', line 163

def logfile_size
  logfile_size = config_get('syslog_settings', 'logfile_size')
  if logfile_size.is_a?(Array)
    logfile_size = (logfile_size[0] == 'no') ? nil : logfile_size[1]
  end
  logfile_size
end

#monitorObject



74
75
76
77
78
79
80
# File 'lib/cisco_node_utils/syslog_settings.rb', line 74

def monitor
  monitor = config_get('syslog_settings', 'monitor')
  if monitor.is_a?(Array)
    monitor = monitor[0] == 'no' ? 'unset' : monitor[1]
  end
  monitor
end

#monitor=(severity) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/cisco_node_utils/syslog_settings.rb', line 82

def monitor=(severity)
  if severity
    config_set(
      'syslog_settings', 'monitor',
      state: '', severity: severity)
  else
    config_set(
      'syslog_settings', 'monitor',
      state: 'no', severity: '')
  end
end

#source_interfaceObject



98
99
100
101
# File 'lib/cisco_node_utils/syslog_settings.rb', line 98

def source_interface
  i = config_get('syslog_settings', 'source_interface')
  i.nil? ? default_source_interface : i.downcase
end

#source_interface=(name) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
# File 'lib/cisco_node_utils/syslog_settings.rb', line 103

def source_interface=(name)
  if name
    config_set(
      'syslog_settings', 'source_interface',
      state: '', source_interface: name)
  else
    config_set(
      'syslog_settings', 'source_interface',
      state: 'no', source_interface: '')
  end
end

#timestampObject Also known as: time_stamp_units



115
116
117
# File 'lib/cisco_node_utils/syslog_settings.rb', line 115

def timestamp
  config_get('syslog_settings', 'timestamp')
end

#timestamp=(val) ⇒ Object Also known as: time_stamp_units=



119
120
121
122
123
124
125
126
127
128
# File 'lib/cisco_node_utils/syslog_settings.rb', line 119

def timestamp=(val)
  fail TypeError \
    unless %w(seconds milliseconds).include?(val.to_s)

  # There is no unset version as timestamp has a default value
  config_set('syslog_settings',
             'timestamp',
             state: '',
             units: val)
end