I’m pretty new to Mikrotik and so I’m still hitting walls with some basic things … like all the dark corners of scripting. The docs aren’t that bad, but mostly focus on adding things and not so much of removing them. Thus there are examples on how to add logging rule, for instance:
But I’m struggling to remove this. WinBox won’t do for me, I want the config scripts to do cleanup before setting things. If they don’t, the rules for the same topics with the same action will just keep piling up. I managed to remove action using numbers=[find where name=”myname”but couldn’t find the appropriate numbers= expression to remote the rule? Yes, for custom actions it is possible to remove the action first and then remote the rules using it with [find invalid]but that won’t work for built in actions like memory that can’t be removed.
So please, anybody, how to write correct /system logging remove to delete the above rule?
Generally, you can just reverse the attributes used in the add and use them in a remove [find ...]. find returns matching .id, and remove can take an *1 that can be used to remove. Now, RouterOS scripting has "types", so topics is an array type. So this one is a bit tricker to remove, as written in OP example. The answer is:
This is because the find will internally :tostr the topics array, which gets ; separators which is presented to find as string. And, the ~, instead of =, just means use a regular express to do a substring search.
Often it helps to add a comment and look for that to remove.
But/system/logging does not have comment, so this does not work:
/system logging add topics=dhcp,info action=memory comment="dhcp log"
/system logging remove [find comment="dhcp log"]
This means you can change other settings in log rule, yet still remove it by a stable thing like comment.
topics is actually an array so if you want to match topics=dhcp,info you'll need to write the [find] condition similar to this
# this dump the item to shows that the correct item has been matched
:put [/system/logging/get [find where ((topics)->0)="dhcp" ((topics)->1)="info" ]]
So, to remove, you can use the command:
/system/logging/remove [find where ((topics)->0)="dhcp" ((topics)->1)="info"]
EDIT: I forgot about the conversion to string, so @Amm0's solution with topics~"dhcp;info" is better. However, in this case no comment can be set for /system/logging entries, so the solution with comment matching is not applicable.
I don't change the messages, but I add to them if there's anything to add. U nose r extended again. Thanks to Carlo Lorenzini, everyone knows what that means.
It's a shame that on this forum there's a pencil mark, which indicates that a post has been edited.
And the moderators can see how it looked before.
You changed it, adding the line
Just think about how to ensure the uniqueness of a rule with the same topics and action
(and there's absolutely nothing wrong with that, especially since mine was just a joke, note the emoticon)
after you read that, about something needed to be written in the comment, on successive posts,
you at 07:15pm, after my post at 07:05pm [what I see on my browser] (where I write "But the right way is to use comment...").
But to avoid writing exactly the same thing, you implied that you were the user somehow must personalize the record.
And then liar about what? Where is the lie?
and where is the other one or the others?
After reading the other topic, I find why you wrote in that way:
Is about using third-party libraries without checking what's written inside, whether the code is an example and is used or not...
Whatever happens, it's certainly not you who judges whether I'm a liar or not, about something unspecified,
but all the users on the forum, who certainly count more than you.
Visible EDIT: I corrected some English meaning, which could be misleading, and added some comments.
There's a post on this forum where you call yourself paranoid and your date calculations are simply ridiculous. I added the advice about the importance of uniqueness after seeing a lot of (in my opinion) incorrect advice on using themes and actions, which I literally pointed out in my post. That's how it all is explained. And this is already your third lie