Skip to content

Commit 9d4b9b6

Browse files
authored
Support modifying syslog server config (#135)
1 parent e94f625 commit 9d4b9b6

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

cterasdk/core/syslog.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from .base_command import BaseCommand
44
from ..common import Object
55
from ..core.enum import Severity, Mode, IPProtocol
6+
from ..exception import CTERAException
67

78

89
class Syslog(BaseCommand):
@@ -47,6 +48,39 @@ def enable(self, server, port=514, proto=IPProtocol.UDP, min_severity=Severity.I
4748
logging.getLogger().info('Syslog enabled.')
4849
return response
4950

51+
def modify(self, server=None, port=None, proto=None, min_severity=None):
52+
"""
53+
Modify Syslog log forwarding configuration
54+
55+
:param str server: Syslog server address
56+
:param int,optional port: Syslog server port
57+
:param cterasdk.core.enum.IPProtocol,optional proto: Syslog server IP protocol
58+
:param cterasdk.core.enum.Severity,optional min_severity: Minimum log severity to forward
59+
"""
60+
current_config = self.get_configuration()
61+
if current_config.mode == Mode.Disabled:
62+
raise CTERAException("Syslog configuration cannot be modified when disabled")
63+
if server:
64+
current_config.server = server
65+
if port:
66+
current_config.port = port
67+
if proto:
68+
current_config.proto = proto
69+
if min_severity:
70+
current_config.minSeverity = min_severity
71+
72+
logging.getLogger().info("Updating syslog server configuration.")
73+
self._portal.put('/settings/logsSettings/syslogConfig', current_config)
74+
logging.getLogger().info(
75+
"Syslog server configured. %s",
76+
{
77+
'server': current_config.server,
78+
'port': current_config.port,
79+
'protocol': current_config.proto,
80+
'minSeverity': current_config.minSeverity
81+
}
82+
)
83+
5084
def disable(self):
5185
logging.getLogger().info('Disabling syslog.')
5286
response = self._portal.put('/settings/logsSettings/syslogConfig/mode', Mode.Disabled)

0 commit comments

Comments
 (0)