Ad Widget

Collapse

Monitoring shell scripts

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • higi
    Junior Member
    • May 2018
    • 6

    #1

    Monitoring shell scripts

    Hi,

    what i want to do is to monitor some of our shells scripts.
    for example simple backup scripts:

    backup_mongo.sh
    Code:
    #!/bin/bash
    TIME=`date +%Y-%m-%d`
    
    mongodump --host localhost --port 27017 --db mongo --collection profilInstance --out - | gzip > /opt/backup_local/mongodb_$TIME.gz

    backup_postgresql.sh
    Code:
    #!/bin/bash
    TIME=`date +%Y-%m-%d`
    
    pg_dumpall -h localhost -p 5432 -U postgres > /opt/backup_local/all_$TIME.gz
    What i want todo is to monitor if script backup_mongo.sh / backup_postgresql.sh finished successfully.
    Create "Graph" where i can see every day marked that mongo/psql was finished 1(ok) / 0 (failed)
    Create "Trigger" so it will send warning if mongo/psql was finished 0 (failed)

    Was googling like few hours and i wasnt able to do it properly. (i am a noob) Please dont post any links to stackoverflow etc, saw them allready. (still i couldnt get it working)

    If can anyone please post real "step by step guide"(for noobs like me). Including changes to my shell scripts, what to do on client (agent) side and Zabbix server side.

    Or maybe someone can help me to setup it on teamviewer.

    THX for any HELP.

    (sorry my english is bad)

  • higi
    Junior Member
    • May 2018
    • 6

    #2
    Anyone please? I will donate or is there any payed support witch could solve my problem?

    Comment

    • edu_tomasi
      Junior Member
      • Jan 2017
      • 5

      #3
      I have a question, how you execute your scripts on the host? It is in crontab or anything like this?

      Comment

      • Engraf
        Member
        • Sep 2014
        • 41

        #4
        You can use error code if it provided by dump utils. You can use zabbix_sender for this. Just add to your script somth. like this:
        Code:
        echo $? > dmputil.err
        <path_to>/zabbix_sender -z <zabbix_server_ip> -i dmputil.err
        Look here: https://www.zabbix.com/documentation.../zabbix_sender

        Comment

        • higi
          Junior Member
          • May 2018
          • 6

          #5
          crontab
          # m h dom mon dow command
          20 23 * * * su -l postgres -c "/opt/_shell/_psql_backup.sh > /tmp/psql_backup.log" 2>/dev/null
          54 2 * * * /opt/_shell/_mongodb_backup.sh
          35 23 * * * /opt/_shell/_jackrabbit_backup_gz.sh
          * 22 * * * /opt/_shell/_renewssl.sh
          Originally posted by edu_tomasi
          I have a question, how you execute your scripts on the host? It is in crontab or anything like this?

          Comment

          • edu_tomasi
            Junior Member
            • Jan 2017
            • 5

            #6
            Originally posted by higi
            crontab
            # m h dom mon dow command
            20 23 * * * su -l postgres -c "/opt/_shell/_psql_backup.sh > /tmp/psql_backup.log" 2>/dev/null
            54 2 * * * /opt/_shell/_mongodb_backup.sh
            35 23 * * * /opt/_shell/_jackrabbit_backup_gz.sh
            * 22 * * * /opt/_shell/_renewssl.sh
            Before make any change in your files (config/scripts) do a backup of the working files.

            Well one way to monitor the status of your shell scripts is by UserParameter.
            First you need to write de status of your script to an log file.
            Ex.:
            Code:
            #!/bin/bash
            TIME=`date +%Y-%m-%d`
            
            mongodump --host localhost --port 27017 --db mongo --collection profilInstance --out - | gzip > /opt/backup_local/mongodb_$TIME.gz
            echo $? > /var/log/mongodb_bkp.log
            Then you can set an UserParameter to read this file (in the host that execute the backup), UserParameters need to be defined in zabbix_agentd.conf.
            Ex.:

            Code:
            echo "UserParameter=mongodb.bkp.status,cat /var/log/mongodb_bkp.log" >> /path/to/zabbix_agentd.conf
            Then the last step is create an item in your Zabbix Server (the item may be created in the host that the backup run).
            The Item will have the key that we defined at second step (mongodb.bkp.status).

            All os this steps you can search at Zabbix Documentation, but if you have any trouble msg me!

            Comment

            • higi
              Junior Member
              • May 2018
              • 6

              #7
              Originally posted by Engraf
              You can use error code if it provided by dump utils. You can use zabbix_sender for this. Just add to your script somth. like this:
              Code:
              echo $? > dmputil.err
              <path_to>/zabbix_sender -z <zabbix_server_ip> -i dmputil.err
              Look here: https://www.zabbix.com/documentation.../zabbix_sender
              Hello,

              created item key:
              Type= Zabbix Agent
              key= mongodb.bkp.status
              Type of information= Numeric (unsigned)
              Show value= As is
              rest are empty

              Have Created Graph on item mongodb.bkp.status

              trying to get this one work, but it doesnt seems to send any value: (allways failed: 1

              zabbix_sender -vv -z 1.2.3.4 -s example.com --tls-connect psk --tls-psk-identity PSK_001 --tls-psk-file /etc/zabbix/zabbix_agentd.psk -k mongodb.bkp.status -o 0


              zabbix_sender [26307]: DEBUG: In zbx_tls_init_child()
              zabbix_sender [26307]: DEBUG: OpenSSL library (version OpenSSL 1.0.1t 3 May 2016) initialized
              zabbix_sender [26307]: DEBUG: zbx_tls_init_child() loaded PSK identity "PSK_001"
              zabbix_sender [26307]: DEBUG: zbx_tls_init_child() loaded PSK from file "/etc/zabbix/zabbix_agentd.psk"
              zabbix_sender [26307]: DEBUG: zbx_tls_init_child() PSK ciphersuites: PSK-AES128-CBC-SHA
              zabbix_sender [26307]: DEBUG: End of zbx_tls_init_child()
              zabbix_sender [26308]: DEBUG: In zbx_tls_connect(): psk_identity:"PSK_001"
              zabbix_sender [26308]: DEBUG: zbx_psk_client_cb() requested PSK identity "PSK_001"
              zabbix_sender [26308]: DEBUG: End of zbx_tls_connect():SUCCEED (established TLSv1.2 PSK-AES128-CBC-SHA)
              zabbix_sender [26308]: DEBUG: answer [{"response":"success","info":"processed: 0; failed: 1; total: 1; seconds spent: 0.000095"}]
              info from server: "processed: 0; failed: 1; total: 1; seconds spent: 0.000095"
              sent: 1; skipped: 0; total: 1

              Can u help please?
              THX

              Comment

              • higi
                Junior Member
                • May 2018
                • 6

                #8
                Originally posted by edu_tomasi

                Before make any change in your files (config/scripts) do a backup of the working files.

                Well one way to monitor the status of your shell scripts is by UserParameter.
                First you need to write de status of your script to an log file.
                Ex.:
                Code:
                #!/bin/bash
                TIME=`date +%Y-%m-%d`
                
                mongodump --host localhost --port 27017 --db mongo --collection profilInstance --out - | gzip > /opt/backup_local/mongodb_$TIME.gz
                echo $? > /var/log/mongodb_bkp.log
                Then you can set an UserParameter to read this file (in the host that execute the backup), UserParameters need to be defined in zabbix_agentd.conf.
                Ex.:

                Code:
                echo "UserParameter=mongodb.bkp.status,cat /var/log/mongodb_bkp.log" >> /path/to/zabbix_agentd.conf
                Then the last step is create an item in your Zabbix Server (the item may be created in the host that the backup run).
                The Item will have the key that we defined at second step (mongodb.bkp.status).

                All os this steps you can search at Zabbix Documentation, but if you have any trouble msg me!
                Hi,

                Awesome got this one working TY

                Right now its working like it checks that file every 30s and write its value to Zabbix db, with is good, but i want to write Value only if i run specific shell script,. Thats why i wanted to try Zabbix_sender and send values when shell script done, but cannot get this one working as on perevious post.
                any help on this one? THX

                Comment

                • geeta
                  Junior Member
                  • Jun 2018
                  • 1

                  #9
                  Thanks a lot got my answer in comment quick. I am going to implement the given instruction.

                  Comment

                  Working...