Ad Widget

Collapse

Javascript item - write on filesystem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TheBonaZabbix
    Member
    • Feb 2023
    • 67

    #1

    Javascript item - write on filesystem

    Hello to all.
    I wrote an Item script.
    The script (javascript) works correctly but I can’t do one thing.
    I would like the script to write inside a file.
    I tried to insert these lines of code but I get an error

    const fs = require('fs'); -> error on this line
    ...
    const filename = '/usr/lib/zabbix/externalscripts/Devices/${params.serial}.json';
    fs.writeFileSync(filename, devicesJSON, 'utf8');

    Do you know if you can do what I want ?
    Thank you !

    Click image for larger version

Name:	image.png
Views:	158
Size:	14.9 KB
ID:	471103​​
  • dimir
    Zabbix developer
    • Apr 2011
    • 1080

    #2
    Zabbix does not allow importing any modules. Also you won't be able to access the filesystem. These restrictions are there for security reasons. What would you like to achieve?

    Comment

    • TheBonaZabbix
      Member
      • Feb 2023
      • 67

      #3
      Thanks for the answer Dimir !
      I think (I hope) I’ve figured it out.
      I made an Item (Get_Info) that runs the script.
      This script returns data in JSON format

      I have created 3 more Get_Info Dependent Items that extract the desired value through preprocessing.

      Do you think I’m on the right track ?

      Thank you very much
      Andrea

      This is the Master Item that get the Json information

      Click image for larger version

Name:	image.png
Views:	149
Size:	28.2 KB
ID:	471124

      This is a Depend Item that filter the Json and populate the correspondign Inventory Field​
      Click image for larger version

Name:	image.png
Views:	138
Size:	23.8 KB
ID:	471125
      Click image for larger version

Name:	image.png
Views:	133
Size:	14.5 KB
ID:	471126

      Comment

      • dimir
        Zabbix developer
        • Apr 2011
        • 1080

        #4
        Yes, you are doing it very right! :-)

        Comment

        • TheBonaZabbix
          Member
          • Feb 2023
          • 67

          #5
          Thanks for your support !

          Have a good day.
          Buona giornata !

          Comment

          Working...