Skip to content

Commit

Permalink
[CMK-2057] - updated beta scripts and tools
Browse files Browse the repository at this point in the history
- supported windows 8(minimal level), tested with clean system
- improved errorlevel processing
- zipall and zip log make zip files instead of 7z
- readme.md is more or less correct and detailed
- switch from 'net <cmd>' to 'sc <cmd>' as more correct

Change-Id: Ieabd7255f35438cc6cd3dd97eb1374b6ed21a306
  • Loading branch information
Sergey Kipnis committed May 22, 2019
1 parent a8bcbd4 commit de4ac63
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 54 deletions.
14 changes: 8 additions & 6 deletions agents/wnx/test_files/beta/clean_files.bat
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
@echo off
setlocal ENABLEDELAYEDEXPANSION
sc query checkmkservice 2> nul > nul
if not "%errorlevel%" == "1060" (
powershell Write-Host Uninstall New Windows Agent before cleaning -Foreground Cyan
exit 0
if !errorlevel! NEQ 1060 (
powershell Write-Host Please, uninstall New Windows Agent before cleaning folders -Foreground Cyan
exit /B 0
)
powershell Write-Host Windows Agent is not installed your can clean folders safely. -Foreground Green
CHOICE.exe /M "Do you really want to remove folders(this is safe)"
if "%errorlevel%" == "1" (

powershell Write-Host New Windows Agent is not installed and you can clean agents folders safely -Foreground Green
CHOICE.exe /M "Remove Windows Agent folders(this is safe) ?"
if !errorlevel! == 1 (
DEL /F/Q/S "%ProgramData%\CheckMk\Agent\*.*" > nul
DEL /F/Q/S "%ProgramFiles(x86)%\check_mk_service" > nul
powershell Write-Host Done... -Foreground Green
Expand Down
4 changes: 2 additions & 2 deletions agents/wnx/test_files/beta/closefirewall.cmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@echo off
set port=6556
if not "%1" == "" set port=%1
@netsh advfirewall firewall delete rule name="CheckMK Windows Agent IN" > nul
if "%errorlevel%" == "0" powershell Write-Host Firewall closed New Windows Agent -Foreground Green & exit /B 0
netsh advfirewall firewall delete rule name="CheckMK Windows Agent IN" > nul
if %errorlevel% == 0 powershell Write-Host Firewall closed New Windows Agent -Foreground Green & exit /B 0
19 changes: 8 additions & 11 deletions agents/wnx/test_files/beta/lwa_enable.cmd
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
@echo off
setlocal enabledelayedexpansion enableextensions
set lwa=check_mk_agent
set wnx=checkmkservice
net session 2> nul > nul
if %errorlevel% NEQ 0 powershell Write-Host "Administrative Rights are required to run this Script" -Foreground Red && exit /B 1
powershell Write-Host "'New' Agent Service stopping..." -Foreground Cyan
net stop %wnx% 2> nul > nul
if "%errorlevel%" == "2" powershell Write-Host "'New' Agent Service already stopped" -Foreground Green && goto next
if not "%errorlevel%" == "0" powershell Write-Host "Failed Stop 'NEW' Agent Service" -Foreground Yellow
:next
sc config "%wnx%" start= disabled > nul
if not "%errorlevel%" == "0" powershell Write-Host "Failed Disable 'NEW' Agent Service, Error=[%errorlevel%]" -Foreground Yellow
sc config "%lwa%" start= auto > nul
if not "%errorlevel%" == "0" powershell Write-Host "Failed Enable 'LEGACY' Agent Service, Error=[%errorlevel%]" -Foreground Yellow

sc stop %wnx% > nul || set e=!errorlevel! && powershell Write-Host "Cant Stop 'New' Agent Service [!e!]" -Foreground Yellow
sc config "%wnx%" start= disabled > nul || set e=!errorlevel! && powershell Write-Host "Cant Disable 'New' Agent Service [!e!]" -Foreground Yellow
sc config "%lwa%" start= auto > nul || set e=!errorlevel! && powershell Write-Host "Cant Enable 'Legacy' Agent Service [!e!]" -Foreground Yellow

powershell Write-Host "'Legacy' Agent Service starting..." -Foreground Cyan
net start %lwa% 2> nul > nul
if "%errorlevel%" == "2" powershell Write-Host "'Legacy' Agent Service already started" -Foreground Green && set errorlevel=0 && goto end
if not "%errorlevel%" == "0" powershell Write-Host "Failed Start 'Legacy' Agent Service, Error=[%errorlevel%]" -Foreground Red && exit 1
sc query %lwa% | find "RUNNING" > nul && powershell Write-Host "'Legacy' Agent Service already running" -Foreground Green && exit /B 0
sc start %lwa% > nul || set e=!errorlevel! && powershell Write-Host "Cant Start 'Legacy' Agent Service [!e!]" -Foreground Yellow && exit /B 1
powershell Write-Host "'Legacy' Agent Service started successfully" -Foreground Green
:end
7 changes: 4 additions & 3 deletions agents/wnx/test_files/beta/openfirewall.cmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@echo off
set port=6556
if not "%1" == "" set port=%1
@netsh advfirewall firewall delete rule name="CheckMK Windows Agent IN" > nul
@netsh advfirewall firewall add rule name="CheckMK Windows Agent IN" description="check_mk new windows agent incoming rule" dir=in localport=%port% protocol=tcp action=allow program="%ProgramFiles(x86)%\check_mk_service\check_mk_agent.exe" profile=private,domain,public enable=yes > nul
if "%errorlevel%" == "0" powershell Write-Host Firewall opened port '%port%' for New Windows Agent -Foreground Green & exit /B 0
netsh advfirewall firewall delete rule name="CheckMK Windows Agent IN" > nul
netsh advfirewall firewall add rule name="CheckMK Windows Agent IN" description="check_mk new windows agent incoming rule" dir=in localport=%port% protocol=tcp action=allow program="%ProgramFiles(x86)%\check_mk_service\check_mk_agent.exe" profile=private,domain,public enable=yes > nul
if %errorlevel% == 0 powershell Write-Host Firewall opened port '%port%' for New Windows Agent -Foreground Green & exit /B 0
powershell Write-Host Firewall failed to open port '%port%' for New Windows Agent -Foreground Yellow
65 changes: 46 additions & 19 deletions agents/wnx/test_files/beta/readme.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,80 @@
# Short Description of files
# Beta-Version of New "Windows Agent" of "Check MK Monitoring Software 1.6"

## Files

* check_mk_agent.msi - installer
* clean_files.bat - remove all files after uninstallation
* lwa_enable.cmd - switch ON Legacy agent
* wnx_enable.cmd - switch ON New agent
## About beta testing

*The New Windows Agent is designed to be safe, i.e. non-intrusive and non-destructive.
This is one of the our design targets. This fact gives us possibility to install and remove
the New Agent relativeley safely even on a computer system used in production.*

Algorithm
* **Install** MSI
* checking/testing
* **Uninstall** Check MK Service
* **lwa_enable.cmd**

## Files description

* check_mk_agent.msi - agent installer
* clean_files.bat - removes all files after uninstallation
* lwa_enable.cmd - switches ON Legacy agent and OFF New one
* wnx_enable.cmd - switches ON New agent and OFF Legacy one
* readme.md - this readme
* openfirewall.cmd - opens firewall for the agent
* closefirewall.cmd - closes firewall back

## Testing requirements

* Check MK 1.5.0
* Administrative Rights for EVERY Run Command
## Testing requirements

## Files&Folders
* [mandatory] Windows 2008R2/Windows or newer
* [recommended] Check MK 1.5.0 with installed Windows Agent
* [mandatory] Administrative Rights for to run any Command

* Core files(not user) are in the "%ProgramFiles(x86)%\check_mk_service"
* User files are in the "%ProgramData%\CheckMk\Agent"
* YML to edit is "%ProgramData%\CheckMk\Agent\check_mk.user.yml"
* Log File is "%Public%\check_mk.log"

## Preinstall

* Run *openfirewall.cmd*


## Clean Install

Assuming you have no Legacy Windows agent:
* Run *check_mk_agent.msi* as ADMIN. **Do not change installation folder**
* Use your monitoring site to get information
* Use *check_mk.user.yml* to change behavior of the agent


## Upgrade mode

* You have to have 1.5 Agent installed
Assuming you have 1.5 Windows Agent installed:
* Run *check_mk_agent.msi* as ADMIN. **Do not change installation folder**
* Use your monitoring site to get information
* New agent stops and disables Legacy agent
* New agent also reuses check_mk.ini and plugins from Legacy agent
* Important: New agent stops and disables Legacy agent
* Safety: New Agent doesn't change Legacy agent files and settings
* Important: New agent also reuses check_mk.ini and plugins from Legacy agent


## Misc

* You may use *lwa_enable.cmd* and *wnx_enable.cmd* too switch between agents
* You may use *lwa_enable.cmd* and *wnx_enable.cmd* too switch between agents, both command are safe to use


## Reporting

* You can use supplied zipall.cmd or ziplog.cmd and send obtained file to sk@mathias-kettner.de or skipnis@gmail.com

## Uninstallation

* Using Control Panel or supplied msi
* Using Control Panel (or msi-file)
* Optionally you can clean files from the disk with *clean_files.cmd*
* If you have Legacy Agent, please, call *lwa_enable.cmd* to reenable it
* Run *closefirewall.cmd*

## New Agent Files&Folders

* Core files of agent are located now in the "%ProgramFiles(x86)%\check_mk_service"
* User files are located in the "%ProgramData%\CheckMk\Agent"
* YML with user settings: "%ProgramData%\CheckMk\Agent\check_mk.user.yml"
* The Log File is "%Public%\check_mk.log"


19 changes: 8 additions & 11 deletions agents/wnx/test_files/beta/wnx_enable.cmd
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
@echo off
setlocal enabledelayedexpansion enableextensions
set lwa=check_mk_agent
set wnx=checkmkservice
net session 2> nul > nul
if %errorlevel% NEQ 0 powershell Write-Host "Administrative Rights are required to run this Script" -Foreground Red && exit /B 1
powershell Write-Host "'Legacy' Agent Service stopping..." -Foreground Cyan
net stop %lwa% 2> nul > nul
if "%errorlevel%" == "2" powershell Write-Host "'Legacy' Agent Service already stopped" -Foreground Green && goto next
if not "%errorlevel%" == "0" powershell Write-Host "Failed Stop 'Legacy' Agent Service [%errorlevel%]" -Foreground Yellow
:next
sc config "%lwa%" start= disabled > nul
if not "%errorlevel%" == "0" powershell Write-Host "Failed Disable 'Legacy' Agent Service, Error=[%errorlevel%]" -Foreground Yellow
sc config "%wnx%" start= auto > nul
if not "%errorlevel%" == "0" powershell Write-Host "Failed Enable 'New' Agent Service, Error=[%errorlevel%]" -Foreground Yellow

sc stop %lwa% > nul || set e=!errorlevel! && powershell Write-Host "Cant Stop 'Legacy' Agent Service [!e!]" -Foreground Yellow
sc config %lwa% start= disabled > nul || set e=!errorlevel! && powershell Write-Host "Cant Disable 'Legacy' Agent Service [!e!]" -Foreground Yellow
sc config %wnx% start= auto > nul || set e=!errorlevel! && powershell Write-Host "Cant Enable 'New' Agent Service [!e!]" -Foreground Yellow

powershell Write-Host "'New' Agent Service starting..." -Foreground Cyan
net start %wnx% 2> nul > nul
if "%errorlevel%" == "2" powershell Write-Host "'New' Agent Service already started" -Foreground Green && set errorlevel=0 && goto end
if not "%errorlevel%" == "0" powershell Write-Host "Failed Start 'New' Agent Service, Error=[%errorlevel%]" -Foreground Red && exit 1
sc query %wnx% | find "RUNNING" > nul && powershell Write-Host "'New' Agent Service already running" -Foreground Green && exit /B 0
sc start %wnx% > nul || set e=!errorlevel! && powershell Write-Host "Cant Start 'New' Agent Service [!e!]" -Foreground Yellow && exit /B 1
powershell Write-Host "'New' Agent Service started successfully" -Foreground Green
:end
2 changes: 1 addition & 1 deletion agents/wnx/test_files/beta/zipall.cmd
Original file line number Diff line number Diff line change
@@ -1 +1 @@
@7z\7z a -r wnx_all "%ProgramData%\CheckMK" "%ProgramFiles(x86)%\check_mk_service" "%Public%\check_mk.*" 2> nul > nul
@7z\7z a -r -tzip wnx_all "%ProgramData%\CheckMK" "%ProgramFiles(x86)%\check_mk_service" "%Public%\check_mk.*" 2> nul > nul
2 changes: 1 addition & 1 deletion agents/wnx/test_files/beta/ziplog.cmd
Original file line number Diff line number Diff line change
@@ -1 +1 @@
@7z\7z a -r wnx_log "%Public%\check_mk.*" 2> nul > nul
@7z\7z a -r -tzip wnx_log "%Public%\check_mk.*" 2> nul > nul

0 comments on commit de4ac63

Please sign in to comment.