Ad Widget

Collapse

Custom button widget

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • StakFallT
    Junior Member
    • Apr 2025
    • 10

    #1

    Custom button widget

    I'm trying to create a custom widget in the form of a button that when configured with values, it can execute an item on a host. For example, right now, I have Zabbix monitoring our on-prem servers for available Windows updates those servers are sitting on. I've done this by adding a Windows by Zabbix agent item on the server's host page under Data collection | Hosts. The item's key value is essentially "system.run[powershell.exe <...> -File <path>\Get_PendingUpdates.ps1]". I then whitelisted this in the config file of the Zabbix daemon running on that server. The output of this script is used what the content to be displayed (essentially the PowerShell script's output is just a single line per update description -- which shows in the Windows update screen). What I'd like to do is have a button I can add to my Servers dashboard page, next to each server, that says "Install updates", and basically just does an item.execute action for the item id of a script that would (I say "would" here, because I don't have such a script written yet) install the updates. I'm close I think, but the best results I can get is for the POST response to come back saying "You are logged in as "Admin". You have no permissions to access this page.". My guess is the csrf token or something. One of the things I tried, as one of my last attempts, was to create a WidgetExecute class that exended the CControllerItemExecuteNow class so that I can have myt WidgetView that contains the button to perform the action POSTing the data to the execute class and have its doAction create a task array and then do something like:

    Code:
    $result = (bool) API::Task()->create($create_tasks);
    $this->setResponse(new CControllerResponseData(['main_block' => json_encode($output)]));
    I get the arguments "You shouldn't do such a thing (creating buttons to execute stuff on servers remotely, etc.); it's not safe.", "Why don't you have Windows Updates do <this>", etc. The Windows Updates thing was just an example. The idea for my button widget is something generic enough that I can wire up in its form properties (specify which already existing host / item id) to execute and execute when the button is clicked. What do I need to do to actually make this button work as desired? My belief is that the way such a thing works is the button element would POST "form"-data (essentially a tiny super-simple little html form container containing only a couple of variables that would be used as the values to the necessary json fields) to zabbix.php with the action. But I don't know, I'm obviously dabbling into some pretty technical backend stuff of how the frontend bridges over to the backend. Thanks in advance!
    Last edited by StakFallT; 10-09-2025, 14:15.
  • cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    #2
    Sounds like you try to reinvent a script that can be executed via host menu?

    Comment

    • StakFallT
      Junior Member
      • Apr 2025
      • 10

      #3
      Not quite. I want to trigger that script so that I can be looking at a list of my servers and just click the button next to them instead of navigating out of the dashboard. My thought is to trigger that script via clicking the button. It's the code of the button widget I created that I can't seem to get right so that it does that triggering. I'm also not using Host Cards just because there's not really a point for that widget to take up screen real-estate. I basically have the layout as each server has 4 gauges (C: free space, CPU Util, CPU queue length, and Memory Util) then underneath that, stretching the width of those 4 gauges, is the output for what updates are available. On the very right side of the dashboard, I have Azure Advanced Threat Protection Sensor readings (in a column) for each server that has that installed and running. So the dashboard I made is pretty condensed. It'd be nice to just have a button(s) for each of the servers to do various things (depending on what script id I have the button set to.
      Last edited by StakFallT; 11-09-2025, 13:58.

      Comment

      • StakFallT
        Junior Member
        • Apr 2025
        • 10

        #4
        I realized I couldn't edit the post to provide even better clarification and then I also realized that I can't do HTML (for colors, to be more precise in my elaboration) in just a simple comment (otherwise I would have done either of those instead of another actual post)...

        Essentially what I want to do is this... You know how if you go to a host's "page" (I say "page" because I'm not sure what exactly you would call it since it's not really the "dashboard" anymore) and you go into the host's items? For example, under the left-pane the navigation path: Monitoring | Hosts then left-click the host name under the Name column, then click Items under the CONFIGURATION section in the context menu. Next scroll down to the item (in this case, and for the example of checking for Windows updates, the item list entry would have the name "Windows by Zabbix agent: Get list of available updates") and click the "..." that's just to the left of the name. Next click "Execute now" under the ACTIONS section of the context menu.

        Well that's what I'd like the button to trigger (basically, the "Execute now" on that item from my dashboard). And yes, I know about triggers, but I don't always want something to execute upon a certain event. When it comes to something like this, I want to be the one to manually trigger something because I may believe the readings I'm seeing are not caused by what usually would be or maybe I just think that it's been a while since I did something so I'll trigger "it" (whatever "it" may be). And what I just said is all instinctual, and /or based on an understanding of factors that may not be being brought into account. To put it in tl;dr terms: There are known knowns, known unknowns, and unknown unknowns. It's not always a known known, so I want to be able to manually trigger an item by button
        Last edited by StakFallT; 12-09-2025, 14:07.

        Comment

        Working...