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:
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!
Code:
$result = (bool) API::Task()->create($create_tasks); $this->setResponse(new CControllerResponseData(['main_block' => json_encode($output)]));
(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
Comment