forked from openzfs/zfs
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
zed -d path/to/zed.d -p path/to/pid.txt -s path/to/zed.state -f Add simple zedlet and support functions Add all-debug.ps1 example, which uses zed-function.ps1 to post Notification on events. More work needed, in particular to make scripts run in the background rather than being waited upon. Signed-off-by: Jorgen Lundman <[email protected]>
- Loading branch information
Showing
24 changed files
with
1,249 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
use_clang() | ||
|
||
um_add_executable(zed | ||
zed.c | ||
zed_conf.c | ||
zed_disk_event.c | ||
zed_event.c | ||
zed_file.c | ||
zed_log.c | ||
zed_strings.c | ||
agents/fmd_api.c | ||
agents/fmd_serd.c | ||
agents/zfs_agents.c | ||
agents/zfs_diagnosis.c | ||
agents/zfs_mod.c | ||
agents/zfs_retire.c | ||
os/windows/zed_exec.c | ||
os/windows/resource.rc | ||
) | ||
target_link_libraries(zed PRIVATE | ||
# libnvpair | ||
# libuutil | ||
libzfs | ||
# libzfs_core | ||
libzpool | ||
) | ||
|
||
target_include_directories(zed PRIVATE "${CMAKE_SOURCE_DIR}/cmd/zed" "${CMAKE_SOURCE_DIR}/include") | ||
|
||
install(TARGETS zed RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") | ||
install(FILES $<TARGET_PDB_FILE:zed> | ||
DESTINATION "${CMAKE_INSTALL_BINDIR}" | ||
OPTIONAL | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// {{NO_DEPENDENCIES}} | ||
// Microsoft Visual C++ generated include file. | ||
// Used by resource.rc | ||
// | ||
|
||
// Next default values for new objects | ||
// | ||
#ifdef APSTUDIO_INVOKED | ||
#ifndef APSTUDIO_READONLY_SYMBOLS | ||
#define _APS_NEXT_RESOURCE_VALUE 101 | ||
#define _APS_NEXT_COMMAND_VALUE 40001 | ||
#define _APS_NEXT_CONTROL_VALUE 1000 | ||
#define _APS_NEXT_SYMED_VALUE 101 | ||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// Microsoft Visual C++ generated resource script. | ||
// | ||
#include <windows.h> | ||
#include "resource.h" | ||
|
||
#define APSTUDIO_READONLY_SYMBOLS | ||
///////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Generated from the TEXTINCLUDE 2 resource. | ||
// | ||
#include "winres.h" | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
#undef APSTUDIO_READONLY_SYMBOLS | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
// English (United States) resources | ||
|
||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) | ||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US | ||
#pragma code_page(1252) | ||
|
||
#ifdef APSTUDIO_INVOKED | ||
///////////////////////////////////////////////////////////////////////////// | ||
// | ||
// TEXTINCLUDE | ||
// | ||
|
||
1 TEXTINCLUDE | ||
BEGIN | ||
"resource.h\0" | ||
END | ||
|
||
2 TEXTINCLUDE | ||
BEGIN | ||
"#include ""winres.h""\r\n" | ||
"\0" | ||
END | ||
|
||
3 TEXTINCLUDE | ||
BEGIN | ||
"\r\n" | ||
"\0" | ||
END | ||
|
||
#endif // APSTUDIO_INVOKED | ||
|
||
#endif // English (United States) resources | ||
///////////////////////////////////////////////////////////////////////////// | ||
|
||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
// English (India) resources | ||
|
||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENN) | ||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_INDIA | ||
#pragma code_page(1252) | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Version | ||
// | ||
|
||
VS_VERSION_INFO VERSIONINFO | ||
FILEVERSION 1,0,0,1 | ||
PRODUCTVERSION 1,0,0,1 | ||
FILEFLAGSMASK 0x3fL | ||
#ifdef _DEBUG | ||
FILEFLAGS 0x1L | ||
#else | ||
FILEFLAGS 0x0L | ||
#endif | ||
FILEOS 0x40004L | ||
FILETYPE 0x1L | ||
FILESUBTYPE 0x0L | ||
BEGIN | ||
BLOCK "StringFileInfo" | ||
BEGIN | ||
BLOCK "400904b0" | ||
BEGIN | ||
VALUE "CompanyName", "TODO: <Company name>" | ||
VALUE "FileDescription", "zed.exe" | ||
VALUE "FileVersion", "1.0.0.1" | ||
VALUE "LegalCopyright", "Copyright (C) 2021" | ||
VALUE "OriginalFilename", "resource.rc" | ||
VALUE "ProductName", "zed.exe" | ||
VALUE "ProductVersion", "1.0.0.1" | ||
END | ||
END | ||
BLOCK "VarFileInfo" | ||
BEGIN | ||
VALUE "Translation", 0x4009, 1200 | ||
END | ||
END | ||
|
||
#endif // English (India) resources | ||
///////////////////////////////////////////////////////////////////////////// | ||
|
||
|
||
|
||
#ifndef APSTUDIO_INVOKED | ||
///////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Generated from the TEXTINCLUDE 3 resource. | ||
// | ||
|
||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
#endif // not APSTUDIO_INVOKED | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/powershell | ||
# shellcheck disable=SC2154 | ||
# | ||
# Log all environment variables to ZED_DEBUG_LOG. | ||
# | ||
# This can be a useful aid when developing/debugging ZEDLETs since it shows the | ||
# environment variables defined for each zevent. | ||
|
||
if (Test-Path "$env:ZED_ZEDLET_DIR\zed.rc") { | ||
. "$env:ZED_ZEDLET_DIR\zed.rc" | ||
} | ||
if (Test-Path "$env:ZED_ZEDLET_DIR\zed-functions.ps1") { | ||
. "$env:ZED_ZEDLET_DIR\zed-functions.ps1" | ||
} | ||
|
||
# | ||
# all-debug.ps1 | ||
# | ||
|
||
Write-Host "all-debug.ps1 is running" | ||
|
||
$envVar = $env:ZED_ZEDLET_DIR | ||
if ($envVar) { | ||
Write-Host "ZED_ZEDLET_DIR is set to: $envVar" | ||
} else { | ||
Write-Host "ZED_ZEDLET_DIR is not set." | ||
} | ||
|
||
Show-ToastNotification -Title "POOL: $env:ZEVENT_POOL" -Message "Event $env:ZEVENT_SUBCLASS has occurred." | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# zed-functions.ps1 | ||
# | ||
# 2024 Jorgen Lundman <[email protected]> | ||
# | ||
|
||
# This one doesn't need any extra PS modules, but is | ||
# ugly. | ||
function Show-PlainToastNotification { | ||
param ( | ||
[string]$Title = "ZED Notification", | ||
[string]$Message = "Default message" | ||
) | ||
|
||
# Load the required assemblies | ||
Add-Type -AssemblyName System.Windows.Forms | ||
Add-Type -AssemblyName System.Drawing | ||
|
||
# Create a form to act as a notification | ||
$form = New-Object System.Windows.Forms.Form | ||
$form.StartPosition = 'Manual' | ||
$form.Location = New-Object System.Drawing.Point(0, 0) | ||
$form.Size = New-Object System.Drawing.Size(300, 100) | ||
$form.FormBorderStyle = 'None' | ||
$form.BackColor = [System.Drawing.Color]::White | ||
$form.TopMost = $true | ||
$form.ShowInTaskbar = $false | ||
$form.Opacity = 0.9 | ||
|
||
# Create a label for the title | ||
$titleLabel = New-Object System.Windows.Forms.Label | ||
$titleLabel.Text = $Title | ||
$titleLabel.Font = New-Object System.Drawing.Font("Arial", 14, [System.Drawing.FontStyle]::Bold) | ||
$titleLabel.AutoSize = $true | ||
$titleLabel.Location = New-Object System.Drawing.Point(10, 10) | ||
|
||
# Create a label for the message | ||
$messageLabel = New-Object System.Windows.Forms.Label | ||
$messageLabel.Text = $Message | ||
$messageLabel.AutoSize = $true | ||
$messageLabel.Location = New-Object System.Drawing.Point(10, 40) | ||
|
||
# Add the labels to the form | ||
$form.Controls.Add($titleLabel) | ||
$form.Controls.Add($messageLabel) | ||
|
||
# Show the form | ||
$form.Show() | ||
|
||
# Timer to close the notification after 5 seconds | ||
$timer = New-Object System.Windows.Forms.Timer | ||
$timer.Interval = 5000 # milliseconds | ||
$timer.Add_Tick({ | ||
$form.Close() | ||
$timer.Stop() | ||
}) | ||
$timer.Start() | ||
|
||
# Run the form's message loop | ||
[System.Windows.Forms.Application]::Run($form) | ||
} | ||
|
||
# For real notifications to work, run in powershell (Admin) | ||
# "Install-Module -Name BurntToast -Force -AllowClobber" | ||
# Failing that, fall back to a regular MessageBox | ||
function Show-ToastNotification { | ||
param ( | ||
[string]$Title = "Notification", | ||
[string]$Message = "This is a test notification." | ||
) | ||
|
||
# Check if the BurntToast module is available | ||
if (Get-Module -ListAvailable -Name BurntToast) { | ||
try { | ||
# Import the module | ||
Import-Module BurntToast -ErrorAction Stop | ||
|
||
# Create a BurntToast notification | ||
New-BurntToastNotification -Text $Title, $Message | ||
} | ||
catch { | ||
# If there's an error, fall back to a basic notification | ||
Write-Host "BurntToast failed to create a notification: $_" | ||
Show-MessageBox "$Message" "$Title" | ||
} | ||
} | ||
else { | ||
# Fallback if BurntToast is not installed | ||
Write-Host "BurntToast module is not installed. Falling back to basic notification." | ||
Show-MessageBox "$Message" "$Title" | ||
} | ||
} | ||
|
||
# Function to show a message box | ||
function Show-MessageBox { | ||
param ( | ||
[string]$Message, | ||
[string]$Title | ||
) | ||
|
||
# Load the necessary assembly | ||
Add-Type -AssemblyName System.Windows.Forms | ||
|
||
# Display the message box | ||
[System.Windows.Forms.MessageBox]::Show($Message, $Title) | ||
} | ||
|
||
|
Oops, something went wrong.