Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    [SOLVED] Cronjob & Script to sending Heartbeat (by url / IP) to external (for example StatusCake) server

    Scheduled Pinned Locked Moved General pfSense Questions
    6 Posts 2 Posters 836 Views
    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.
    • Sergei_ShablovskyS
      Sergei_Shablovsky
      last edited by Sergei_Shablovsky

      Hi, pfSense Gurus!

      Could You be so please to suggest me .sh script to making “heartbeat” to external server outside pfSense?

      For example, so-called “Push URL “ for StatusCake service:

      https://push.statuscake.com/?PK=abc123&TestID=123456&time=0.
      

      Parsing the answer not needed, only checking by ping and sending heartbeat if ping are ok. And write appropriate string with timestamp into syslog (or separate log) file.

      Thank You so much!

      —
      CLOSE SKY FOR UKRAINE https://youtu.be/_tU1i8VAdCo !
      Help Ukraine to resist, save civilians people’s lives !
      (Take an active part in public protests, push on Your country’s politics, congressmans, mass media, leaders of opinion.)

      1 Reply Last reply Reply Quote 0
      • Sergei_ShablovskyS
        Sergei_Shablovsky
        last edited by

        Creating cronjob successfully, but curl cannot working as needed:

        from shell CLI
        curl ‘https://push.statuscake.com/?PK=123456789&TestID=987654321&time=0’
        return ‘success’

        BUT when the same string put in .sh file
        the same command
        curl ‘https://push.statuscake.com/?PK=123456789&TestID=987654321&time=0’
        lead to error in log
        ‘curl: (3) URL rejected: Port number was not a decimal number between 0 and 65535’

        What I am doing wrong?

        —
        CLOSE SKY FOR UKRAINE https://youtu.be/_tU1i8VAdCo !
        Help Ukraine to resist, save civilians people’s lives !
        (Take an active part in public protests, push on Your country’s politics, congressmans, mass media, leaders of opinion.)

        E 1 Reply Last reply Reply Quote 0
        • E
          elvisimprsntr @Sergei_Shablovsky
          last edited by elvisimprsntr

          @Sergei_Shablovsky

          1. Need to specify the entire path for curl
          /usr/local/bin/curl
          
          
          1. Make sure the .sh file has execute permissions
          chmod a+x {filename}
          
          1. Include the shebang in the .sh file
          #!/bin/sh
          
          
          Sergei_ShablovskyS 1 Reply Last reply Reply Quote 1
          • Sergei_ShablovskyS
            Sergei_Shablovsky @elvisimprsntr
            last edited by Sergei_Shablovsky

            @elvisimprsntr said in Cronjob & Script to sending Heartbeat (by url / IP) to external StatusCake server:

            @Sergei_Shablovsky

            1. Need to specify the entire path for curl
            /usr/local/bin/curl
            
            

            Done.

            1. Make sure the .sh file has execute permissions
            chmod a+x {filename}
            

            Already done.

            1. Include the shebang in the .sh file
            #!/bin/sh
            
            

            Already done.

            But result are the same:
            (In initial question I forgot to write that this is arpwatch message)
            —-

            pf.local.lan
            pf.local.lan - Arpwatch Notification : Cron <root@pf> /usr/local/bin/pingtest_statuscake.sh - 
            
            
            X-Cron-Env: <SHELL=/bin/sh>
            X-Cron-Env: <PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin>
            X-Cron-Env: <LOGNAME=root>
            X-Cron-Env: <USER=root>
            
            curl: (3) URL rejected: Port number was not a decimal number between 0 and 65535
            

            ——

            —
            CLOSE SKY FOR UKRAINE https://youtu.be/_tU1i8VAdCo !
            Help Ukraine to resist, save civilians people’s lives !
            (Take an active part in public protests, push on Your country’s politics, congressmans, mass media, leaders of opinion.)

            1 Reply Last reply Reply Quote 0
            • Sergei_ShablovskyS
              Sergei_Shablovsky
              last edited by Sergei_Shablovsky

              [SOLVED] need to put URL between “ and #!/bin/sh:

              #!/bin/sh
              curl “https://push.statuscake.com/?PK=123456789&TestID=987654321&time=0”
              

              Thank You all here!

              —
              CLOSE SKY FOR UKRAINE https://youtu.be/_tU1i8VAdCo !
              Help Ukraine to resist, save civilians people’s lives !
              (Take an active part in public protests, push on Your country’s politics, congressmans, mass media, leaders of opinion.)

              1 Reply Last reply Reply Quote 1
              • Sergei_ShablovskyS
                Sergei_Shablovsky
                last edited by Sergei_Shablovsky

                Little update for this shell script in case You have MULTIPLE WAN (and need testing each uplink connection):

                THIS SCRIPT SENDS HEARTBEAT ON ONE (1) CERTAIN TEST ID.

                So, if You need really monitoring all WANS and receiving SEPARATE ALERT on EACH WAN,- You may create several Tests on StatusCake and USING V.2 OF THIS SCRIPT

                #!/bin/sh
                
                # HEARTBEAT to StatusCake external monitoring and alerting service
                
                # Examples and additional information 
                # https://www.statuscake.com/kb/knowledge-base/what-is-push-monitoring/
                
                # Successfully working on pfSense CE 2.7.X
                
                # List of network interfaces
                INTERFACES="igb10 igb11 igb12 igb13"
                
                # StatusCake URL
                URL="https://push.statuscake.com/?PK=123456764226&TestID=7347942&time=0""
                
                # Loop through each interface and send a curl request
                for INTERFACE in $INTERFACES
                do
                    echo "Sending request through interface $INTERFACE"
                    /usr/local/bin/curl --interface "$INTERFACE" "$URL"
                    echo "" # Print a newline for better readability
                done
                

                YOU MAY TEST exactly script from Diagnostic / Command Shell TO ENSURE THAT ALL ARE WORKING as expected!

                The result MUST be looks like this:

                Sending request through interface igb0
                  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                                 Dload  Upload   Total   Spent    Left  Speed
                
                  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
                100     7  100     7    0     0     12      0 --:--:-- --:--:-- --:--:--    12
                success
                Sending request through interface igb1
                  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                                 Dload  Upload   Total   Spent    Left  Speed
                
                  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
                  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
                100     7  100     7    0     0     13      0 --:--:-- --:--:-- --:--:--    13
                success
                Sending request through interface igb2
                  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                                 Dload  Upload   Total   Spent    Left  Speed
                
                  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
                100     7  100     7    0     0     13      0 --:--:-- --:--:-- --:--:--    13
                success
                Sending request through interface igb3
                  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                                 Dload  Upload   Total   Spent    Left  Speed
                
                  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
                  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
                100     7  100     7    0     0     13      0 --:--:-- --:--:-- --:--:--    13
                success
                

                P.S.
                1.
                After testing on exactly Your setup, You MUST comment both ‘echo’ command to avoid unnecessary output to terminal.
                2.
                logger’ command not using also: because of a lot of calling (1 time / min, 1 time / 5 min,…) system log would be filled by unnecessary records that not helping You even when You have automatic log aggregator & analyser like Splunk, ELK, Graylog,….

                —
                CLOSE SKY FOR UKRAINE https://youtu.be/_tU1i8VAdCo !
                Help Ukraine to resist, save civilians people’s lives !
                (Take an active part in public protests, push on Your country’s politics, congressmans, mass media, leaders of opinion.)

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post
                Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.