Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changes cisco_fxos_sensors to base on entity_sensors (reopen PR) #363

Closed
wants to merge 3 commits into from

Conversation

thl-cmk
Copy link
Contributor

@thl-cmk thl-cmk commented Apr 15, 2021

-> remove fxos files
-> split entity_sensors.py in utils/enttity_sensors.py end entity_sensors.py
-> new cisco_entity_sensors.py: register.snmp/parse function (not for undefined/temp) -> checks in entity_sensors.py
-> new test_cisco_entity_sensors.py

Known Issues:
-> Service name for power_presence "Power Sensor" overlaps with power_consumption sensors -> change to "Power supply"
-> default values lower for fan are in conflict with device status -> needs options like 'temperature'
-> some ASA devices have no valid scaling value (always 1), posible workaround:
in "parse_entity_sensors" check scaling value -> if 1 change to 9

Posible improvements:
-> WATO: hw_fan.py -> change "output_metrics" -> CheckBox to FixedValue -> on click less ;-)
-> name field in EntitySensor is not used -> can be removed

-> remove *fxos* files
-> split entity_sensors.py in utils/enttity_sensors.py end entity_sensors.py
-> new cisco_entity_sensors.py: register.snmp/parse function (not for undefined/temp) -> checks in entity_sensors.py
-> new test_cisco_entity_sensors.py

Known Issues:
-> Service name for power_presence "Power Sensor" overlaps with power_consumption sensors -> change to "Power supply"
-> default values lower for fan are in conflict with device status -> needs options like 'temperature'
-> some ASA devices have no valid scaling value (always 1), posible workaround:
   in "parse_entity_sensors" check scaling value -> if 1 change to 9

Posible improvements:
-> WATO: hw_fan.py -> change "output_metrics" -> CheckBox to FixedValue -> on click less ;-)
-> name field in EntitySensor is not used -> can be removed
Copy link
Contributor

@jherbel jherbel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides some minor issues, we should discuss the known issues you mentioned:

  • Service name for power_presence "Power Sensor" overlaps with power_consumption sensors -> change to "Power supply"
    Where exactly does this overlap occur? Within this plugin or are there overlaps with another plugin?
  • default values lower for fan are in conflict with device status -> needs options like 'temperature'
    Can this for the moment be overcome by changing the lower levels with a rule?
  • some ASA devices have no valid scaling value (always 1), posible workaround:
    in "parse_entity_sensors" check scaling value -> if 1 change to 9
    What value do we get from entPhySensorScale report in such cases?

item: str,
params: TempParamType,
section: EntitySensorSection,
item: str,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please undo these changes

item: str,
params: Mapping[str, Any],
section: EntitySensorSection,
item: str,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please undo these changes

item: str,
params: Mapping[str, Any],
section: EntitySensorSection,
item: str,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please undo these changes

)

from cmk.base.plugins.agent_based.entity_sensors import (
check_entity_sensors_fan,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any tests for entity_sensors should be implemented in test_entity_sensors.py. Here, you should only test the parse function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any tests for entity_sensors should be implemented in test_entity_sensors.py. Here, you should only test the parse function.

Ok, so i move the test over to test_entity_sensors.py (except for the parse section), or is there than no additional testing nessecary? And I can remove these additional tests?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move them over

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. If I move the discover function tests we will still use functions from both plugins. Is this ok.
e.g. "discover_entity_sensors_power_presence" and "parse_cisco_entity_sensors" in "test_discover_entity_sensors_power_presence"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, its better to not mix that. Just copy _section over to the other file. Also, I guess the discovery and the check function are well tested, so there is no need to add that many tests.

# this MIB, thus we use OID as item instead

# do not add undefined and temp sensors (duplicate with cisco_temperature)
if sensor_type_nr not in ['0', '8']:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have quite some duplicate code here. It would be better to define a generic parse function in utils/entity_sensors.py which takes an additional input argument
sensor_types_ignore: Container[str]
You can then use this function for both snmp sections, for example

def parse_entity_sensors(string_table: List[StringTable]):
    return utils.parse_entity_sensors(string_table, set())

@thl-cmk
Copy link
Contributor Author

thl-cmk commented Apr 16, 2021

Besides some minor issues, we should discuss the known issues you mentioned:

  • Service name for power_presence "Power Sensor" overlaps with power_consumption sensors -> change to "Power supply"
    Where exactly does this overlap occur? Within this plugin or are there overlaps with another plugin?
    true, to a other plugin, at the moment it's a CheckPoint/Dell Server, this has a Power supply presence/function sensor and a Power consumtion sensor, so in the long run it would make sense to have a common naming over all these type of plugins. Might be better to change it now before the plugin is out with the next public release.
  • default values lower for fan are in conflict with device status -> needs options like 'temperature'
    Can this for the moment be overcome by changing the lower levels with a rule?
    it could, but it's kind of ugly
  • some ASA devices have no valid scaling value (always 1), posible workaround:
    in "parse_entity_sensors" check scaling value -> if 1 change to 9
    What value do we get from entPhySensorScale report in such cases?
    The device reports 1, meaning 10**(-24)

@jherbel
Copy link
Contributor

jherbel commented Apr 16, 2021

true, to a other plugin, at the moment it's a CheckPoint/Dell Server, this has a Power supply presence/function sensor and a Power consumtion sensor, so in the long run it would make sense to have a common naming over all these type of plugins. Might be better to change it now before the plugin is out with the next public release.

which plugin?

The device reports 1, meaning 10**(-24)

Can 1 ever be correct? Do we have a way of knowing?

@thl-cmk
Copy link
Contributor Author

thl-cmk commented Apr 16, 2021

true, to a other plugin, at the moment it's a CheckPoint/Dell Server, this has a Power supply presence/function sensor and a Power consumtion sensor, so in the long run it would make sense to have a common naming over all these type of plugins. Might be better to change it now before the plugin is out with the next public release.

which plugin?
checkpoint_sensors, not yet public ;-)

The device reports 1, meaning 10**(-24)

Can 1 ever be correct?
for fan speed I think 1 can't never be correct or it must be a very slow fan
for temp, I think also not, at least for a sensor
Do we have a way of knowing?
I think not realy. In my option the best way would be to have some kind of option for the parse function, so this could become configurable.

From the MIB description of sensorValue: "Range: -1000000000 - 1000000000"
so a fan with sensorValue = 1000000000 (max) and sensorScale =1 (as reported) will rotate at 9.999999999999999e-16 RPM
this must be a kind of very acurate sensor to measure this little value, I think this is true for temp also

@jherbel
Copy link
Contributor

jherbel commented Apr 16, 2021

checkpoint_sensors, not yet public ;-)

Ok, in that case, everything is fine I would say, since its not even a plugin which is part of Checkmk

From the MIB description of sensorValue: "Range: -1000000000 - 1000000000"
so a fan with sensorValue = 1000000000 (max) and sensorScale =1 (as reported) will rotate at 9.999999999999999e-16 RPM
this must be a kind of very acurate sensor to measure this little value, I think this is true for temp also

Then it would probably make sense to simply hard-code this. I.e., neither temperature nor fan sensors should ever have sensorScale =1 and if this occurs, we set sensorScale =9. However, I would suggest do this afterwards in a separate PR afterwards (small bugfix).

@thl-cmk
Copy link
Contributor Author

thl-cmk commented Apr 16, 2021

checkpoint_sensors, not yet public ;-)

Ok, in that case, everything is fine I would say, since its not even a plugin which is part of Checkmk

This is not entirely true, these checks are already there (except for the Power consumption) but sitll in /checks.
Especially checkpoint_powersupply, where the service name is "Power Supply". Basically this is the same as the entity_sensors_power check. Just curious, why is this such a problem to straighten the names?

From the MIB description of sensorValue: "Range: -1000000000 - 1000000000"
so a fan with sensorValue = 1000000000 (max) and sensorScale =1 (as reported) will rotate at 9.999999999999999e-16 RPM
this must be a kind of very acurate sensor to measure this little value, I think this is true for temp also

Then it would probably make sense to simply hard-code this. I.e., neither temperature nor fan sensors should ever have sensorScale =1 and if this occurs, we set sensorScale =9. However, I would suggest do this afterwards in a separate PR afterwards (small bugfix).

Ok. could look like this in the parse function:

if sensor_type_nr in ["8", "10"] and scaling_nr == "1":
            scaling_nr = "9"

@jherbel
Copy link
Contributor

jherbel commented Apr 16, 2021

This is not entirely true, these checks are already there (except for the Power consumption) but sitll in /checks.
Especially checkpoint_powersupply, where the service name is "Power Supply". Basically this is the same as the entity_sensors_power check. Just curious, why is this such a problem to straighten the names?

Ah sry, I thought you meant check plugins that you had lying around locally or something. In general, changing service descriptions is problematic, since it can affect a lot of customers (you have to maybe changes rules etc.). I don't see the overlap between checkpoint_powersupply and entity_sensors. checkpoint_powersupply has
'service_description': "Power Supply %s",
and entity_sensors_power_presence has
service_name='Power %s',
However, in entity_sensors, we always have "Sensor" in the item name (_reformat_sensor_name).

Ok. could look like this in the parse function:
if sensor_type_nr in ["8", "10"] and scaling_nr == "1":
scaling_nr = "9"

Yes, but as I said, please in a separate commit afterwards.

@thl-cmk
Copy link
Contributor Author

thl-cmk commented Apr 16, 2021

Ah sry, I thought you meant check plugins that you had lying around locally or something.....
I understand that, on the other hand, it is very annoying when you have products from different vendors and the "basically" same thing in CMK has different functions and names. In this case, for example, I couldn't just say that all power sensors are shown globally because they have different names. The scond thing, this check is very new, meaning not a lot of custumers will have this yet. So changing it now will be more easy than later when every one is using it. But in the end your decission.

One more thing about the naming. A quick grep over your code base shows, that most of this checks use the term "Power supply" (18), some use "Powersupply" (2) or "Power supply satus" (2). and there is at least one "Power consumtion" check (fsc_sc2_power_consumption).

@jherbel
Copy link
Contributor

jherbel commented Apr 16, 2021

Ok, what exactly do you want to rename into what?

@thl-cmk
Copy link
Contributor Author

thl-cmk commented Apr 16, 2021

From:

    service_name='Power %s',

to:

    service_name='Power Supply %s',

@jherbel
Copy link
Contributor

jherbel commented Apr 16, 2021

For now, we leave this as it is.

Copy link
Contributor

@jherbel jherbel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unit tests for the parse function can all be moved to .../utils/test_entity_sensors.py. There, you can tests cases with and without exclusion.

section: EntitySensorSection = {}
sensor_names = {i[0]: i[1] for i in string_table[0]}
for oid_end, sensor_type_nr, scaling_nr, reading, status_nr, device_unit in string_table[1]:
if sensor_type_nr not in sensor_types_ignore:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if sensor_type_nr in sensor_types_ignore: 
    continue

this avoid indenting the whole block afterwards



def parse_entity_sensors(string_table: List[StringTable],
sensor_types_ignore: Optional[Container[str]] = None) -> EntitySensorSection:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use set() here (and typization Container[str])

@thl-cmk
Copy link
Contributor Author

thl-cmk commented Apr 20, 2021

The unit tests for the parse function can all be moved to .../utils/test_entity_sensors.py. There, you can tests cases with and without exclusion.

You mean the last test in .../utils/test_cisco_entity_sensors.py? Even if then have a cross reference betwen entity_sensors and cisco_entity_sensors? If yes, I will then remove .../utils/test_cisco_entity_sensors.py completely.

@jherbel
Copy link
Contributor

jherbel commented Apr 20, 2021

You mean the last test in .../utils/test_cisco_entity_sensors.py? Even if then have a cross reference between entity_sensors and cisco_entity_sensors? If yes, I will then remove .../utils/test_cisco_entity_sensors.py completely.

What I mean is that there is no need to have separate tests for parse_cisco_entity_sensors and entity_sensors.parse_entity_sensors. Simply test the parse function utils.entity_sensors.

Copy link
Contributor

@jherbel jherbel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good from my side, are there any other changes you want to do here? Otherwise Ill go ahead and merge.

@thl-cmk
Copy link
Contributor Author

thl-cmk commented Apr 22, 2021

Hi Joerg,

I think for now we should move forward with this PR. The oher things we discussed, I guess we need to do this at a later time.

/Thomas

@jherbel
Copy link
Contributor

jherbel commented Apr 22, 2021

Ok, then I will go ahead and merge this. Bugfixes (such as the scaling) can be handled in later PRs.

@thl-cmk thl-cmk deleted the cisco_fxos_sensors branch November 25, 2023 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants