Skip to content
Snippets Groups Projects
Commit bde722b9 authored by Andreas Lindemark's avatar Andreas Lindemark
Browse files

First version of the README.md

parent 73976fc8
No related branches found
No related tags found
No related merge requests found
# Some scripts to use with Zabbix Agent
## Overview
This repository contains scripts to
- Remove all remnants of Zabbix Agent and Zabbix Agent 2
- Check if Zabbix Agent 2 is running or not, if not copy the configurartion file from the network and replace it in the installation folder and start up the Zabbix Agent 2 service
## Files
- `CheckAndStartZabbixAgent2.ps1`: Script to check if Zabbix Agent 2 is running or not, if not then copy the configurartion file from the network and replace it in the installation folder and start the Zabbix Agent 2 service.
- `RemoveZabbix.ps1`: Script to emove all remnants of Zabbix Agent and Zabbix Agent 2.
## Usage
1. Download `CheckAndStartZabbixAgent2.ps1` and create a new scheduled task run run this regurarly.
2. Download and run `RemoveZabbix.ps1` to remove all remnants of Zabbix Agent and Zabbix Agent 2.
## Prerequisites
- PowerShell 5.1 or later.
## Download and install
### Via an automatic One-Liner, that Downloads, installs and clean up
This one-liner download and install does the following:
1. Sets the path to store the script.
2. Download the script file to the path.
3. Create a scheduled task.
1. To run the script, you need to temporarily change the PowerShell execution policy to allow script execution. You can do this by using the following one-liner code:
```powershell
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force; $scriptPath = "C:\Windows\System32\Tasks\CheckAndStartZabbixAgent2.ps1"; Invoke-WebRequest -Uri "https://gitlab.liu.se/andli86/snippets/-/raw/master/Windows/ZabbixAgent/CheckAndStartZabbixAgent2.ps1" -OutFile $scriptPath; schtasks /create /tn "CheckAndStartZabbixAgent2" /tr "powershell.exe -File $scriptPath" /sc hourly /mo 3 /ru SYSTEM;
```
## Manual Installation
1. **Download the script file to the computer, I prefer to the `C:\Windows\System32\Tasks\` folder**:
```
https://gitlab.liu.se/andli86/snippets/-/raw/master/Windows/ZabbixAgent/CheckAndStartZabbixAgent2.ps1
```
2. **Configure a Scheduled Task**: Ensure the execution policy allows the script to run.
3. **Test run the script** by manually starting the scheduled task, perhaps with the Zabbix Agent 2 service both Started and Stopped.
When you run the script `CheckAndStartZabbixAgent2.ps1`, it will perform the following actions:
1. **Retrive the Domain name**: ...
2. **Set the source path for the Zabbix Agent 2 configuration file**: ...
3. **Set the target path for the Zabbix Agent 2 configuration file**: ...
4. **Check if Zabbix Agent 2 service is running**: Output the Service status...
- **Running**: Output "Zabbix Agent 2 is already running. No action needed.". And EXIT the script.
- **Stopped**: Call two functions "Copy-ZabbixConfig" and "Start-ZabbixAgent2"
6. **Copy-ZabbixConfig function**: Copies the zabbix_agent2.conf file from the source path to the target path.
7. **Start-ZabbixAgent2 function**: Starts the "Zabbix Agent 2" service.
8. **EXIT**: Exit the script, since we reached the end of the file.
The script provides informative messages about its actions, such as:
- If the Zabbix Agent 2service is running or is stopped.
- Copies the the zabbix_agent2.conf file from the source path to the target path.
- Starts the "Zabbix Agent 2" service, if it was stopped.
## Usage
The scheduled task `CheckAndStartZabbixAgent2` runs the following script `C:\Windows\System32\Tasks\CheckAndStartZabbixAgent2.ps1` every three hours.
## License
This project is licensed under the MIT License. And is provided as-is without any warranty. Use at your own risk.
## Author
Andreas Lindemark, Linköping University
## Contact
For any questions, please contact andreas.lindemark@liu.se.
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment