Ad Widget

Collapse

Newbie's first custom UserParameter

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • snakefox
    Junior Member
    • Jan 2023
    • 11

    #1

    Newbie's first custom UserParameter

    Hello.
    I'm trying to set up a custom UserParameter for a Linux server. I've made the necessary changes:
    Code:
    UserParameter=disk.partition.workload[*],df -k | grep $1 | awk '{print $5}' | sed 's/.$//'
    The idea is that I ask about a specific file system and get in return an integer which I then use in Zabbix triggers. I've tested the command itself and it works exactly as I want it to. But when I try to get the result through Zabbix (or try to test it with following)
    Code:
    zabbix_agentd -t disk.partition.workload[/pcap]
    the result I get is the entire, unformatted string:​
    Code:
    /pcap 54476506720 48636767680 3105006112  94% /pcap
    I don't understand what causes this change and how do I fix it.
  • Answer selected by snakefox at 23-01-2023, 10:34.
    Markku
    Senior Member
    Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
    • Sep 2018
    • 1782

    Zabbix agent is parsing the $5 in the awk command to an empty string (because there is only one parameter given in the item). You need to use double $ as mentioned in the documentation (https://www.zabbix.com/documentation...ser-parameters) or, just like you did, use an external script.

    Markku

    Comment

    • cyber
      Senior Member
      Zabbix Certified SpecialistZabbix Certified Professional
      • Dec 2006
      • 4807

      #2
      Seems to break just before awk...
      You do not mention version of Zabbix, but I tested on 6.0.9 and agent2 and it does the same... But I cannot think of any good solution, too many other things to deal with...

      Comment

      • snakefox
        Junior Member
        • Jan 2023
        • 11

        #3
        Sorry, I am using zabbix_agentd (daemon) (Zabbix) 4.4.9.
        Tried using a bash workaround:
        Code:
        df -k | grep $1 | sed 's/ */ /g' | cut -d" " -f 5 | sed 's/.$//g'
        Worked, so it was definitely awk's fault. Which is weird, because if I put awk in a script and launch the script in the UserParameter, it works.

        Comment

        • Markku
          Senior Member
          Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
          • Sep 2018
          • 1782

          #4
          Zabbix agent is parsing the $5 in the awk command to an empty string (because there is only one parameter given in the item). You need to use double $ as mentioned in the documentation (https://www.zabbix.com/documentation...ser-parameters) or, just like you did, use an external script.

          Markku

          Comment

          • snakefox
            Junior Member
            • Jan 2023
            • 11

            #5
            Huh, this'll hopefully teach me to read documentation better.
            Thanks!

            Comment

            Working...