ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Unsolved I need this script to email the log it generates

    IT Discussion
    scripting email log freepbx
    4
    24
    2.7k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • stacksofplatesS
      stacksofplates @1337
      last edited by

      @Pete-S said in I need this script to email the log it generates:

      @stacksofplates said in I need this script to email the log it generates:

      you could use mailgun. I just wrote this tiny app that will send the contents of a file.

      I lazily take the first argument as the file with the contents you want to send. Just have env vars for the recipient address, your api key and domain (or hard code them). You could take flags and whatever, but this was free and I'm lazy.

      There is one problem with the api approach I think.
      I believe tht if you use postfix to deliver the message over SMTP it will put the message in postfix' queue. So if for some reason the mail can't be delivered at that particular time, for instance because the firewall is being rebooted or there is a problem with the mailservice, it will try again later. Using the API you will just a timeout error and that was it.

      I'm not a mailgun user but I assume they have a SMTP relay as well?

      In any case since we like zoho, I intend to try the new Zoho TransMail service. They only send transactional mail, not marketing, and I think it was $2.5 or something like that per 10K emails. They have both api and SMTP.

      That's no different than postfix. It would be pretty trivial to add a retry block for a timeout condition. Postfix has it built in, you'd need the 5 lines of code here or whatever would be needed. And this will work on literally any system that the binary can be compiled for:

      • aix
      • android
      • darwin
      • dragonfly
      • freebsd
      • hurd
      • illumos
      • js
      • linux
      • nacl
      • netbsd
      • openbsd
      • plan9
      • solaris
      • windows
      • zos
      1 Reply Last reply Reply Quote 1
      • stacksofplatesS
        stacksofplates
        last edited by

        Another plus for an API is that snmp is commonly blocked from providers and only enabled with some kind of request.

        Also if you want to integrate any other notification (text, telegram notification, slack, etc) it would be trivial to add with this approach.

        Not saying API is the best way, but it definitely has advantages.

        JaredBuschJ 1 Reply Last reply Reply Quote 0
        • JaredBuschJ
          JaredBusch @stacksofplates
          last edited by

          @stacksofplates said in I need this script to email the log it generates:

          Another plus for an API is that snmp is commonly blocked from providers and only enabled with some kind of request.

          Also if you want to integrate any other notification (text, telegram notification, slack, etc) it would be trivial to add with this approach.

          Not saying API is the best way, but it definitely has advantages.

          I have not had time to look at what you posted yet but I plan on it thank you

          stacksofplatesS 1 Reply Last reply Reply Quote 1
          • stacksofplatesS
            stacksofplates @JaredBusch
            last edited by

            @JaredBusch said in I need this script to email the log it generates:

            @stacksofplates said in I need this script to email the log it generates:

            Another plus for an API is that snmp is commonly blocked from providers and only enabled with some kind of request.

            Also if you want to integrate any other notification (text, telegram notification, slack, etc) it would be trivial to add with this approach.

            Not saying API is the best way, but it definitely has advantages.

            I have not had time to look at what you posted yet but I plan on it thank you

            Yeah no problem. It's really simple so it could be optimized quite a bit with maybe like 30 mins of work.

            1 1 Reply Last reply Reply Quote 0
            • 1
              1337 @stacksofplates
              last edited by

              @stacksofplates said in I need this script to email the log it generates:

              @JaredBusch said in I need this script to email the log it generates:

              @stacksofplates said in I need this script to email the log it generates:

              Another plus for an API is that snmp is commonly blocked from providers and only enabled with some kind of request.

              Also if you want to integrate any other notification (text, telegram notification, slack, etc) it would be trivial to add with this approach.

              Not saying API is the best way, but it definitely has advantages.

              I have not had time to look at what you posted yet but I plan on it thank you

              Yeah no problem. It's really simple so it could be optimized quite a bit with maybe like 30 mins of work.

              Wouldn't just using curl do the job equally well of sending the message to mailgun?

              stacksofplatesS 1 Reply Last reply Reply Quote 0
              • stacksofplatesS
                stacksofplates @1337
                last edited by

                @Pete-S said in I need this script to email the log it generates:

                @stacksofplates said in I need this script to email the log it generates:

                @JaredBusch said in I need this script to email the log it generates:

                @stacksofplates said in I need this script to email the log it generates:

                Another plus for an API is that snmp is commonly blocked from providers and only enabled with some kind of request.

                Also if you want to integrate any other notification (text, telegram notification, slack, etc) it would be trivial to add with this approach.

                Not saying API is the best way, but it definitely has advantages.

                I have not had time to look at what you posted yet but I plan on it thank you

                Yeah no problem. It's really simple so it could be optimized quite a bit with maybe like 30 mins of work.

                Wouldn't just using curl do the job equally well of sending the message to mailgun?

                Yep. If you really like handling errors and responses in shell scripting it's fine. Unless you use it on Windows where cURL is not really cURL.

                I'm not doing raw API calls with the example above. That's using their Go package which simplifies a lot of the API information.

                1 1 Reply Last reply Reply Quote 0
                • 1
                  1337 @stacksofplates
                  last edited by

                  @stacksofplates said in I need this script to email the log it generates:

                  @Pete-S said in I need this script to email the log it generates:

                  @stacksofplates said in I need this script to email the log it generates:

                  @JaredBusch said in I need this script to email the log it generates:

                  @stacksofplates said in I need this script to email the log it generates:

                  Another plus for an API is that snmp is commonly blocked from providers and only enabled with some kind of request.

                  Also if you want to integrate any other notification (text, telegram notification, slack, etc) it would be trivial to add with this approach.

                  Not saying API is the best way, but it definitely has advantages.

                  I have not had time to look at what you posted yet but I plan on it thank you

                  Yeah no problem. It's really simple so it could be optimized quite a bit with maybe like 30 mins of work.

                  Wouldn't just using curl do the job equally well of sending the message to mailgun?

                  Yep. If you really like handling errors and responses in shell scripting it's fine. Unless you use it on Windows where cURL is not really cURL.

                  I'm not doing raw API calls with the example above. That's using their Go package which simplifies a lot of the API information.

                  OK, I understand. Thanks.

                  How is it with the maintenance with APIs like this? I mean when you compile something and have to support it over time, it's just like being a package maintainer. If they change the API or their Go package or perhaps OS or Go version, you'd have to recompile and redistribute it to every machine. Or is this something that would only happen very seldom like every two years or something like that?

                  stacksofplatesS 2 Replies Last reply Reply Quote 0
                  • stacksofplatesS
                    stacksofplates @1337
                    last edited by stacksofplates

                    @Pete-S said in I need this script to email the log it generates:

                    @stacksofplates said in I need this script to email the log it generates:

                    @Pete-S said in I need this script to email the log it generates:

                    @stacksofplates said in I need this script to email the log it generates:

                    @JaredBusch said in I need this script to email the log it generates:

                    @stacksofplates said in I need this script to email the log it generates:

                    Another plus for an API is that snmp is commonly blocked from providers and only enabled with some kind of request.

                    Also if you want to integrate any other notification (text, telegram notification, slack, etc) it would be trivial to add with this approach.

                    Not saying API is the best way, but it definitely has advantages.

                    I have not had time to look at what you posted yet but I plan on it thank you

                    Yeah no problem. It's really simple so it could be optimized quite a bit with maybe like 30 mins of work.

                    Wouldn't just using curl do the job equally well of sending the message to mailgun?

                    Yep. If you really like handling errors and responses in shell scripting it's fine. Unless you use it on Windows where cURL is not really cURL.

                    I'm not doing raw API calls with the example above. That's using their Go package which simplifies a lot of the API information.

                    OK, I understand. Thanks.

                    How is it with the maintenance with APIs like this? I mean when you compile something and have to support it over time, it's just like being a package maintainer. If they change the API or their Go package or perhaps OS or Go version, you'd have to recompile and redistribute it to every machine. Or is this something that would only happen very seldom like every two years or something like that?

                    I haven't seen it happen much where they would break the API often. If they were to do a big API change like that you'd likely have a good bit of notice. The packages for Go are versioned in the modules, so you can pin them to limit changes.

                    Looks like Mailgun is currently on /v3 of their API but some endpoints still use /v1 or /v2. The package would handle that for you since it's maintained by them.

                    One more advantage specifically with Go, is that you can containerize this easily. This could be done in a scratch container which has 0 dependencies. Then you could just run this with Docker/podman/whatever and easily keep the container up to date across all of your systems. I'm sure Jared wouldn't be doing that here, just a side note.

                    1 Reply Last reply Reply Quote 1
                    • stacksofplatesS
                      stacksofplates @1337
                      last edited by

                      @Pete-S said in I need this script to email the log it generates:

                      OK, I understand. Thanks.

                      Also, I wasn't trying to be abrasive. I kind of worded that strongly. I just don't like Bash much. I find it annoying, so I'd rather use something else unless it's a really simple thing.

                      1 1 Reply Last reply Reply Quote 0
                      • 1
                        1337 @stacksofplates
                        last edited by

                        @stacksofplates said in I need this script to email the log it generates:

                        @Pete-S said in I need this script to email the log it generates:

                        OK, I understand. Thanks.

                        Also, I wasn't trying to be abrasive. I kind of worded that strongly. I just don't like Bash much. I find it annoying, so I'd rather use something else unless it's a really simple thing.

                        No problem. Bash is primitive for sure. Pick the right tool for the job I guess.

                        1 Reply Last reply Reply Quote 0
                        • 1
                        • 2
                        • 2 / 2
                        • First post
                          Last post