Powershell script to install Promtail for Windows hosts to get Windows Events
- Download the script
- Run the script with elevated privileges
- The script will download the latest Promtail version and install it as a service
- Stop the service
- Edit the configuration file located at
C:\Promtail\promtail.yml
- You can run the application in debug mode to check if the configuration is correct.
To do so, run the command:
.\promtail-windows-amd64.exe --config.file=promtail.yml --config.expand-env=true
from theC:\Promtail
directory
Once your configuration is correct, you can start the service:
- Open Windows Services
- Start the service named
Promtail
You can validate the configuration by running the following command:
.\promtail-windows-amd64.exe --config.file=promtail.yml --check-syntax
A default configuration file is installed by the script to get all the Windows Events.
You can modify the configuration file located at C:\Promtail\promtail.yml
to filter the events you want to collect.
You can use xpath_queries to filter the events of interest. Please refer to the Loki documentation for more information.
In order to use an environment variable in the configuration file, you can use the syntax ${ENV_VAR}
.
To avoid having to store a system-wide environment variable, follow the following steps:
- Create a
REG_MULTI_SZ
registry value named Environment underHKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\<service-name-of-Promtail>
- On this multistring value each line represents an environment variable visible only to the specific service.
The syntax of each line is the name of the environment variable followed by an =,
everything after the sign until the end of the line is the value of the environment variable.
For example, for
LOKI_AUTH
add a line like:LOKI_AUTH=<your-value-for-otel-auth>
Thanks to @OndrejValenta for the initial script