Code: Select all
:do {
:local topics {"account"; "critical"; "error"}
:local ident [/system identity get name]
/system logging
remove [find action=sendToSyslog prefix=$ident]
:foreach t in=$topics do={
add topics=$t action=sendToSyslog prefix=$ident
}
} on-error={
:put "Failed to apply logging config!"
}
The above code doesn't configure the "sendToSyslog" action, that can be achieved using something like this:
Code: Select all
:do {
:local syslogServer "1.2.3.4"
/system logging action
remove [find target=remote remote=$syslogServer]
add name=sendToSyslog remote=$syslogServer target=remote
/system logging
remove [find invalid]
} on-error={
:put "Failed to apply logging config!"
}
1) It takes the approach of wiping all "action=sendToSyslog prefix=$ident" rules before running - if you are not OK with this, please modify as desired.
2) Due to the previous point, it should only be used if you want to manage all logging rules with "action=sendToSyslog prefix=$ident", if some other rules exist than specificed in the "topics" variable, they will not be retained.