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

Collect sensor readings from Lenovo/IBM PDUs (Power Distribution Units) #1475

Merged
merged 5 commits into from Mar 10, 2017

Conversation

lunkwill42
Copy link
Member

As requested by SIGMA2, here is basic support for retrieving power readings from phases and outlets on the Lenovo PDUs currently being deployed.

@lunkwill42 lunkwill42 added this to the 4.7.0 milestone Mar 9, 2017
@lunkwill42 lunkwill42 self-assigned this Mar 9, 2017
@lunkwill42 lunkwill42 requested a review from sigmunau March 9, 2017 14:26


class IbmPduMib(MibRetriever):
""" Custom class for retrieveing sensors from APC UPSes."""
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe update docstrings?

Copy link
Member Author

Choose a reason for hiding this comment

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

Definitely :-)

self._logger.debug("Got phase power readings: %r", phases)

result = []
column = self.nodes.get(PHASE_LAST_POWER_READING, None)
Copy link
Contributor

Choose a reason for hiding this comment

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

Either don't put a default here, or do not assume this is not None later in the code

Copy link
Member Author

Choose a reason for hiding this comment

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

A good point. It would be really bad if the OID definition isn't present in the MIB we already compiled ourselves - this is what you get for using older code as inspiration ;)

result = []
for index, row in outlets.items():
for sensor in self._outlet_row_to_sensors(index, row):
result.append(sensor)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe use result.extend() rather than an extra for loop?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes.

description = row.get(OUTLET_DESCRIPTION)

voltage = dict(
oid=str(self.nodes.get(OUTLET_VOLTAGE, None).oid + str(index)),
Copy link
Contributor

Choose a reason for hiding this comment

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

None.oid will not work. If the key is missing it makes more sense to get a KeyError than an AttributeError

yield voltage

current = dict(
oid=str(self.nodes.get(OUTLET_CURRENT, None).oid + str(index)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Again


power = dict(
oid=str(self.nodes.get(OUTLET_LAST_POWER_READING,
None).oid + str(index)),
Copy link
Contributor

Choose a reason for hiding this comment

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

And again :)

@lunkwill42 lunkwill42 merged commit acdb77f into master Mar 10, 2017
@lunkwill42 lunkwill42 deleted the lenovo-pdu branch March 10, 2017 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants