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 5131bab4 authored by thl-cmk's avatar thl-cmk :flag_na:
Browse files

adds --no-default-cfg option

parent 96fd1a5d
No related branches found
No related tags found
No related merge requests found
......@@ -14,13 +14,13 @@ models = []
version = "17.6.4"
md5 = "2caa962f5ed0ecc52f99b90c733c54de"
size = 706565772
models = []
models = ["C1117-4PMLTEEAWE"]
["c1100-universalk9.17.10.01a.SPA.bin"]
version = "17.10.1a"
md5 = "a0cd6218c42f19bed425e3c63a11bcda"
size = 689542648
models = ["C1117-4PMLTEEAWE"]
models = []
["c3560cx-universalk9-mz.152-7.E7.bin"]
version = "15.2(7)E7"
......
......@@ -35,7 +35,7 @@
# 2023-02-23: added cli option -v/--version, --default_cfg
# 2023-02-26: reorganized open-pnp.py in to open_pnp_classes.py and open_pnp_utils.py
# 2023-32-07: changed '_' in cli options to '-' -> better readable/more bash like
#
# 2023-03-13: added '--no-default-cfg' option
#
# pip install flask xmltodict requests ifaddr tomli
#
......@@ -78,7 +78,7 @@ from open_pnp_utils import (
)
PNP_SERVER_VERSION = '20230227.v1.0.2'
PNP_SERVER_VERSION = '20230313.v1.0.3'
def pnp_device_info(udi: str, correlator: str, info_type: str) -> str:
......@@ -161,9 +161,14 @@ def pnp_config_upgrade(udi: str, correlator: str) -> Optional[str]:
cfg_file = f'{device.serial}.cfg'
response = head(f'{SETTINGS.config_url}/{cfg_file}')
if response.status_code != 200: # SERIAL.cfg not found
cfg_file = SETTINGS.default_cfg
response = head(f'{SETTINGS.config_url}/{cfg_file}')
if response.status_code != 200: # DEFAULT.cfg also not found
if not SETTINGS.no_default_cfg:
cfg_file = SETTINGS.default_cfg
response = head(f'{SETTINGS.config_url}/{cfg_file}')
if response.status_code != 200: # DEFAULT.cfg also not found
device.error_code = ERROR.ERROR_NO_CFG_FILE
device.hard_error = True
return
else:
device.error_code = ERROR.ERROR_NO_CFG_FILE
device.hard_error = True
return
......
......@@ -8,6 +8,7 @@
# log_to_file = true
# log_file = "log/pnp_debug.log"
# default_cfg_file = "default.cfg"
# no_default_cfg = false
# image_data = "images.toml"
# image_url = "http://192.168.10.133:8080/images"
# config_url = "http://192.168.10.133:8080/configs"
......
......@@ -8,6 +8,9 @@
# Date : 2023-02-26
# File : open_pnp_classes.py
#
# 2023-03-13: fixed default_cfg option
# added no_default_cfg option
from typing import Dict, Optional, Any
from tomli import load as toml_load
......@@ -20,7 +23,7 @@ class ErrorCodes:
100: 'unknown platform',
101: 'no free space for update',
102: 'unknown image',
103: 'config file not found',
103: 'no config file found',
104: 'image file not found',
1412: 'Invalid input detected (config)',
......@@ -114,6 +117,7 @@ class Settings:
image_url: Optional[str] = '',
config_url: Optional[str] = '',
default_cfg: Optional[str] = 'DEFAULT.cfg',
no_default_cfg: Optional[bool] = False,
):
self.__settings = {
'cfg_file': cfg_file,
......@@ -129,6 +133,7 @@ class Settings:
'image_url': image_url,
'config_url': config_url,
'default_cfg': default_cfg,
'no_default_cfg': no_default_cfg,
}
self.__args = {}
self.__set_cli_args(cli_args)
......@@ -203,6 +208,10 @@ class Settings:
def default_cfg(self) -> str:
return self.__settings['default_cfg']
@property
def no_default_cfg(self) -> bool:
return self.__settings['no_default_cfg']
class SoftwareImage:
def __init__(self, image: str, version: str, md5: str, size: int,):
......
......@@ -8,6 +8,10 @@
# Date : 2023-02-26
# File : open_pnp_utils.py
#
# 2023-03-13: added --no-default-cfg option
#
from typing import List
import logging
from logging.handlers import RotatingFileHandler
......@@ -91,6 +95,9 @@ def parse_arguments(pnp_server_version: str) -> arg_Namespace:
help='Enable Debug output send to "log-file".')
parser.add_argument('--default-cfg', type=str,
help='default config to use if no device specific config is found. (default: DEFAULT.cfg)')
parser.add_argument('--no-default-cfg', default=False, action='store_const', const=True,
help='Disables default config file for PnP devices. This option takes precedence over all '
'"--default-cfg" cli options or config entries.')
parser.add_argument('--log-file', type=str,
help='Path/name of the logfile. (default: log/pnp_debug.log, requires --debug) ')
parser.add_argument('--log-to-console', default=False, action='store_const', const=True,
......
{#
# Author: thl-cmk[at]outlook[dot]com
# URL : https://thl-cmk.hopto.org
# Date : 2022-12-10
# File : status.html
#
# 2023-03-13: moved error columns to debug output
#
#}
{% macro header_row() %}
<tr>
<th>Count</th>
<th>Action</th>
<th>Serial number</th>
<th>Serial number</th>
<th>Platform</th>
<th>HW rev.</th>
<th>HW rev.</th>
<th>IP-Address</th>
<th>PnP flow</th>
<th>PnP flow</th>
<th>Status</th>
<th>First seen</th>
<th>Last contact</th>
<th>Current job</th>
<th>Current version</th>
<th>Target version</th>
<th>First seen</th>
<th>Last contact</th>
<th>Current job</th>
<th>Current version</th>
<th>Target version</th>
<th>Last message</th>
{% if debug %}
<th>Current image</th>
<th>Target image</th>
<th>Current image</th>
<th>Target image</th>
<th>Size</th>
<th>Free space</th>
<th>Free space</th>
<th>Destination</th>
{% endif %}
<!-- <th>Error code</th> -->
<!-- <th>Last error</th> -->
<!-- <th>Last message</th> -->
<!-- <th>Error count</th> -->
<!-- <th>Hard error</th> -->
{% if debug %}
<th>Error code</th>
<th>Last error</th>
<th>Error count</th>
<th>Hard error</th>
<th>Backoff</th>
{% endif %}
</tr>
......@@ -35,9 +46,9 @@
{% set min_rows = 50 %}
{% if devices|length < min_rows %}
{% set current_rows = devices|length %}
{% set num_columns = 17 %}
{% set num_columns = 13 %}
{%if debug %}
{% set num_columns = num_columns + 6 %}
{% set num_columns = num_columns + 10 %}
{% endif %}
{% for i in range (0, min_rows - current_rows) %}
<tr>
......@@ -188,19 +199,17 @@
<td>{{ device.current_job }}</td>
<td>{{ device.version }}</td>
<td>{{ device.target_image.version }}</td>
<td>{{ device.error_code_readable }}</td>
{% if debug %}
<td>{{ device.image }}</td>
<td> <a href="{{ image_base_url }}/{{ device.target_image.image }}" target="_blank">{{device.target_image.image }}</a></td>
<td>{{ device.target_image.size }}</td>
<td>{{ device.destination_free }}</td>
<td>{{ device.destination_name }}</td>
{% endif %}
<!-- <td>{{ device.error_code }}</td> -->
<!-- <td>{{ device.error_code_readable }}</td> -->
<!-- <td>{{ device.error_message }}</td> -->
<!-- <td>{{ device.error_count }}</td> -->
<!-- <td>{{ device.hard_error }}</td> -->
{% if debug %}
<td>{{ device.error_code }}</td>
<td>{{ device.error_message }}</td>
<td>{{ device.error_count }}</td>
<td>{{ device.hard_error }}</td>
<td>{{ device.backoff }}</td>
{% endif %}
</tr>
......
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