Windows版Snaketail外部工具参数配置及触发PHP脚本求助
Hey there, I’ve worked with Snaketail on Windows before, so let’s walk through how to set up keyword-based triggers for your PHP script—since the official docs and GitHub repo don’t cover this, here’s a step-by-step guide that should get you sorted:
How to Trigger a PHP Script on Highlighted Log Lines in Windows Snaketail
Step 1: Create a Highlighting Rule with External Command Trigger
- Open Snaketail, load your target log file, and head to
View > Highlighting Rules(or hitCtrl+Hto open the rules panel). - Click
Addto make a new rule:- In the
Text to findbox, type the keyword (or regex pattern) you want to use to trigger the script. Check theRegular expressionbox if you’re using regex for more complex matches. - Set a highlight style (color, bold, italic) so you can visually confirm when the rule matches—this is optional but helpful for testing.
- Scroll down to the
External commandsection at the bottom of the rule editor. Check the box that saysExecute command when line matches.
- In the
Step 2: Configure the Command to Pass the Log Line to Your PHP Script
This is where you’ll link Snaketail to your PHP script and pass the matched log line.
In the Command line field, enter this (adjust paths to match your setup):
php.exe "C:\full\path\to\your\processing-script.php" "%LINE%"
php.exe: Use the full path to your PHP executable if it’s not in your system PATH (e.g.,C:\Program Files\PHP\8.2\php.exe)."C:\full\path\to\your\processing-script.php": Wrap your script’s full path in quotes to handle spaces in folder/filenames."%LINE%": This is Snaketail’s built-in variable that inserts the entire matched log line as an argument to your script.
Access the Log Line in Your PHP Script
In your PHP script, you can grab the passed log line using the $argv array (PHP’s way of accessing command-line arguments):
<?php // Check if we received a log line argument if (isset($argv[1])) { $triggeredLogLine = $argv[1]; // Do your processing here—example: append to a log, send an alert, parse data file_put_contents("triggered-events.log", $triggeredLogLine . PHP_EOL, FILE_APPEND); } else { // Handle cases where no line was passed error_log("PHP script called without a log line from Snaketail"); } ?>
Step 3: Test and Troubleshoot
- Save your highlight rule, make sure it’s enabled (check the box next to it in the rules list), then generate a log line that matches your keyword. You should see the line highlight, and your script should run automatically.
- If the script doesn’t execute:
- Verify the paths to
php.exeand your script are correct—test the command manually in Command Prompt first to rule out path issues. - Run Snaketail as Administrator if you hit permission errors (some folders restrict external program execution).
- Check your script’s output (like the
triggered-events.login the example) to confirm the log line was received properly.
- Verify the paths to
内容的提问来源于stack exchange,提问作者Kim Steinhaug
相关产品推荐
相关产品推荐

