oxidized icon indicating copy to clipboard operation
oxidized copied to clipboard

Email generation issue

Open BullfroG21 opened this issue 10 years ago • 11 comments

Hi,

first of all thanks for your effort building oxidized.

We are replacing our Rancid/CVS using Oxidized/Git and using also the oxidized-web as interface, and we face a small issue that maybe it’s already solved but we do not find how. We have set the oxidized to send an email after a diff detection. The problem is that the email its launched per device and we would like to change this behavior to get an email per all router.db defined devices after all of them have been checked to avoid many emails in our network list. We already thought of writing the commit ids in a file and then via cron read the commit ids file and compose an email hourly, but we think it’s not the best solution.

Do you have some idea of how to deal with this issue?

Best regards, Florian

BullfroG21 avatar May 02 '16 09:05 BullfroG21

Do you the email hook in extras directory?

There are few things we could do, we could launch a hook after each full rotation (but that is not really guaranteed to be correct, as people can change the order of the rotation, so it would only be correct if order was not changed during given rotation), then you could send diff between previous rotation time and current rotation time.

Another option would be do this in the per commit hook, but only send like one diff per hour, 6 hours, day or something like that, and just return without sending email if it's already been done within that timeframe. You'd need to store the last launch timestamp in some file, and when say 6 hours from that has gone, you'd ask git for diff between the previous timestamp and current timestamp and email that.

ytti avatar May 02 '16 12:05 ytti

Hi ytti,

I am a BullfroG21 colleague that works also in the same project.

Thanks for your response. We actually used our custom mail script but we are trying yours (oxidized-report-git-commits) just now :)

What would be the event to get it run after a full rotation? I just see node_success, post_store, and node_fail. If there is no we will go ussing the timestamps.

Best regards, Albert M.

amarti2038 avatar May 04 '16 09:05 amarti2038

There isn't such event, I'm open to accepting PR for such event added.

ytti avatar May 04 '16 11:05 ytti

I for one would also like this feature - all updates grouped into one email would be amaze.

callumbnz avatar May 08 '16 22:05 callumbnz

Hi again,

After a pause we are again back xD

We think that @ytti in the comment from 2 May tells an interesting approach, because we can "grant" that no one will change the last device from the router.db. If I understand fine, you mean, to create a custom model for one of our devices, place it in the bottom of the router.db and then invoke from this custom model the mailer script. It’s that fine?

The point here is if the execution order from the router.db its followed or not, taking into account the threads. Or should we limit the threads to 1 to force a sequential behavior?

With kind regards, Florian and @amarti2038

BullfroG21 avatar Jun 22 '16 11:06 BullfroG21

Hi @ytti,

After our tests we can iniciate a pull request from all our code, if you thing its usefull.

We just implemented the invokation of the mailer script in a custom model. We do not know if its the cleanest way but it works just fine.

cfg :telnet, :ssh do
    # enable command-line mode on SMB comware switches (HP V1910, V1920)
    # autodetection is hard, because the 'summary' command is paged, and
    # the pager cannot be disabled before _cmdline-mode on.
    if vars :comware_cmdline
      post_login do
        send "_cmdline-mode on\n"
        send "y\n"
        send vars(:comware_cmdline) + "\n"
      end
    end
    post_login 'screen-length disable'
    post_login 'undo terminal monitor'
    pre_logout 'quit'
    sucess = %x( /bin/bash '/usr/local/sbin/oxidized_mailer.sh' )
 end

Currently in all the postcommits we append the commit id in a file that we remove after the mail its send.

In relation to the threads order it do not matther because if the mailer thread lauches before the end of the rotation the next devices will create again the file and insert there their commit ids, then we will fetch them next rotation, the only difference will be that we will get a delay receiving their diffs.

In any way would be nice to control wich device will be the last one. Do you know some way?

Regards, Albert M.

amarti2038 avatar Jul 06 '16 08:07 amarti2038

Wasn't the requirement to do this only after full rotation? Now you're doing it in the model, regardless of change or not? We already have solution to do mailing on actual changes, after each node.

But we don't have solution to do mailing after full rotation, but I'm open for a PR which implements full-rotation hook.

ytti avatar Jul 06 '16 08:07 ytti

Hi @ytti,

we want to generate an email with all node configs diffs inside for all the nodes that changed, but just one mail per a rotation, to avoid multiple mails per rotation.

Our flow its the next:

  1. ussing the "poststore" event we append the commit ids in a file (if file do not exist we create it).
  2. with have a custom model that its configured in the last device of the router.db and this model call our mailer script. sucess = %x( /bin/bash '/usr/local/sbin/oxidized_mailer.sh' )
  3. our mailer script creates the mail body with a loop reading the commid ids file
  4. the email is sended and the commit ids file removed.

The point is that you launch threads and my question is if we can grant that an specific node its invoked the last one of all the nodes rotation.

Best regards, Albert M.

amarti2038 avatar Jul 06 '16 09:07 amarti2038

We don't guarantee order. You can ask any node to be fetched 'now', and when you do, order changes. We don't also guarantee any specific order when you load nodes.

There are several ways to implement once-in-rotation hook, two options would be:

a) maintain counter of nodes attempted, when count of nodes attempted divided by counts of nodes has reminder of 0, reset counter to 0 and launch once-in-rotation hooks (Does not handle adding/removing/reordering nodes)

b) maintain boolean :attempted_at_this_rotation for each node, set to 'false' on load, set to 'true' after processing node. After processing a node, check if all nodes have :attemped_at_this_rotation set to true, if so, call once-in-rotation hook and set :attemped_at_this_rotation false for all. (Handles adding/removing/reordering, but more complex to implement)

ytti avatar Jul 06 '16 10:07 ytti

Hi @ytti,

And there is no posibility of running the oxidized just one rotation via a cron call?, then I will just wait the end of the process and lunch the mailer script.

I am afraid about the thread behaivour, what if the 2 last threads are lunched simultaniosly and the one that call the mailer script perform the action before that the post_store from the other, we would loss the changes from that device.

With the cron we just have to collect commit ids in the post_store and wait till the oxidized process end to generate the mail and send it.

We will also need to run in a separate way the web server but we can easily run just another git web api in php/ruby... maybe also an instance of the oxidized_web :)

What do you think? How we can call from the terminal the oxidized just for one rotation?, we tried with the "interval" but we do not find how.

Albert M.

amarti2038 avatar Jul 06 '16 11:07 amarti2038

The thread behaviour isn't only reason why your solution does not work, in my previous comment I explained that we inherently don't guarantee any order, so even in single threaded instances it wouldn't be guaranteed to work.

The right solution is to implement hook which is called on end-of-iteration.

There isn't currently way to run oxidised for single iteration, but I believe someone else requested it too, so I think it is justifiable and useful to add. I'm not going to do it, not in any near future at any rate. But I happily will accept PR.

Of course to implement this, you need to implement intelligence about what is 'rotation', which means, if you do implement the intelligence, then you can also trivially implement the hook.

ytti avatar Jul 06 '16 12:07 ytti