Collection of CheckMK checks (see https://checkmk.com/). All checks and plugins are provided as is. Absolutely no warranty. Send any comments to thl-cmk[at]outlook[dot]com

Skip to content
Snippets Groups Projects
Commit e86b9207 authored by thl-cmk's avatar thl-cmk :flag_na:
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
# Auto detect text files and perform LF normalization
* text=auto
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
This diff is collapsed.
# SmartMoveHelper
This script replaces [Cisco ASA ASDM](ASDM) inline network groups (_DM_INLINE_NETWORK_xxx_) in
policy import scripts created by [Check Point SmartMove](https://support.checkpoint.com/results/sk/sk115416).
```
python smh.py -h
usage: smh.py [-h] [-s SOURCE_HOST] [-f]
The script replaces ASDM DM_INLINE_NETWORK_ groups with there members in
policy import scripts created by Check Point SmartMove
options:
-h, --help show this help message and exit
-s SOURCE_HOST, --source-host SOURCE_HOST
Name of the source host
-f, --fix-fw1 Replaces "" with "FW1" in policy and objects file
For more information see: https://thl-cmk.hopto.org/gitlab/bits-and-bytes/SmartMoveHelper
Version: 0.0.1-20250325 | Written by: thl-cmk@outlook.com
```
_smh.py_ expects the Check Point SmartMove _**SOURCE_HOST_objects.sh**_ and _**SOURCE_HOST_policy.sh**_ in the same directory as _smh.py_ is running.
smh.py 0 → 100644
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# License: GNU General Public License v3
# Author: thl-cmk[at]outlook[dot]com
# URL : https://thl-cmk.hopto.org
# Date : 2025-03-17
# File : smh.py
"""
replace cisco ASA ASDM DM_INLINE_NETWORK_ groups with there members in Check Point SmartMove policy file
"""
from argparse import (
ArgumentParser,
Namespace,
RawTextHelpFormatter,
)
from dataclasses import dataclass
from pathlib import Path
from sys import exit as sys_exit
__SMH_VERSION__:str = '0.0.1-20250325'
__SMH_AUTHOR__:str = 'thl-cmk@outlook.com'
__SMH_URL__:str = 'https://thl-cmk.hopto.org/gitlab/bits-and-bytes/SmartMoveHelper'
@dataclass
class Args(Namespace):
"""CLI options for easy access in IDE
Args:
Namespace (_type_): ArgumentParser name space
"""
source_host: str
fix_fw1: bool
def parse_arguments() -> Args:
"""Argument parser
Returns:
arg_Namespace: CLI Arguments
"""
parser = ArgumentParser(
prog='smh.py',
description=(
'The script replaces ASDM DM_INLINE_NETWORK_ groups with there members in\n'
'policy import scripts created by Check Point SmartMove\n'
),
formatter_class=RawTextHelpFormatter,
epilog=f'\nFor more information see: {__SMH_URL__}\n'
f'Version: {__SMH_VERSION__} | Written by: {__SMH_AUTHOR__}\n'
)
parser.add_argument(
"-s", "--source-host", type=str,
help='Name of the source host'
)
parser.add_argument(
"-f", "--fix-fw1", action='store_const', const=True, # default=False,
help='Replaces "" with "FW1" in policy and objects file',
)
return parser.parse_args()
def replace_inline_object(position: str, line:str, group_objects: dict) -> str:
"""
Replaces DM_INLINE_NETWORK_XXX with the members of the inline group
Args:
position (str): position of the inline group to replace (source|destination)
line (str): line from the policy script where to replace the inline group(s)
group_objects (dict): dictionary with inline groups name as key and list
of member names as items
Returns:
str: policy script line with inline group replaced by group members
"""
for group_name, group_members in group_objects.items():
if f'{position} "{group_name}"' in line:
count: int = 0
replace_str: str = ''
for member in group_members:
replace_str += f' {position}.{count} "{member}" '
count += 1
line = line.replace(f'{position} "{group_name}"', replace_str)
return line
def get_inline_objects(host_name:str) -> dict[str, list[str]]:
"""Create dictionary of inline groups with there members as items
Args:
host_name (str): name of the source host. smh expects a file
named "host_name_objects.sh" in the same directory
Returns:
dict: dictionary with inline groups name as key and list of member names as items
"""
dm_inline_network: str = "cmd='mgmt_cli add group name \"DM_INLINE_NETWORK_"
inline_objects: dict[str, list[str]] = {}
object_file = Path(f'{host_name}_objects.sh')
if object_file.exists():
raw_objects = object_file.read_text(encoding="UTF-8").splitlines()
raw_inline_objects: list[str] = [
line for line in raw_objects if line.startswith(dm_inline_network)
]
for entry in raw_inline_objects:
entry = entry.split('"')
name = entry[1]
members = [
member for member in entry[2:-3] if not member.strip().startswith("members.")
]
inline_objects[name]=members
print(f"Number of inline groups: {len(inline_objects)}")
else:
print(f"file {object_file.name} not found")
return inline_objects
def fix_fw1_in_objects(host_name: str) -> None:
"""SmartMove has an issue with service 256/TCP (FW1). It will put only
a "" in the policy script instead of "FW1". This function will fix this by replacing
each "" witch "FW1". The result is written to "host_name_objects_fixed_fw1.sh".
Args:
host_name (str): name of the source host. smh expects a file named "host_name_objects.sh"
in the same directory
"""
object_file = Path(f'{host_name}_objects.sh')
if object_file.exists():
raw_text = object_file.read_text(encoding="UTF-8")
fixed_objects = Path(f'{host_name}_objects_fixed_fw1.sh')
fixed_objects.write_text(encoding="UTF-8", data=raw_text.replace('""', '"FW1"'))
print(f"policy written to: {fixed_objects.name}")
def main():
"""Replace all DM_INLINE_NETWORK groups in the policy file with there members.
The result is written to "host_name_policy_no_inline.sh"
"""
args: Args = parse_arguments()
if not args.source_host:
print("Usage:")
print("python convert_inline.py -s <source_host_name> \n\n")
sys_exit(1)
inline_objects: dict[str, list[str]] = get_inline_objects(host_name=args.source_host)
policy_file = Path(f"{args.source_host}_policy.sh")
policy_no_inline: list[str] = []
if policy_file.exists():
raw_policy: list[str] = policy_file.read_text(encoding="UTF-8").splitlines()
for raw_line in raw_policy:
if 'source "DM_INLINE_NETWORK_' in raw_line:
raw_line = replace_inline_object(
position="source", line=raw_line, group_objects=inline_objects
)
if 'destination "DM_INLINE_NETWORK_' in raw_line:
raw_line = replace_inline_object(
position="destination", line=raw_line, group_objects=inline_objects
)
if args.fix_fw1:
raw_line = raw_line.replace('""', '"FW1"')
policy_no_inline.append(raw_line)
policy_no_inline_file = Path(f"{args.source_host}_policy_no_inline.sh")
policy_no_inline_file.write_text(encoding="UTF-8", data="\n".join(policy_no_inline))
print(f"policy written to: {policy_no_inline_file.name}")
if args.fix_fw1:
fix_fw1_in_objects(args.source_host)
else:
print(f"file {policy_file.name} not found")
if __name__ == '__main__':
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment