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

systemd_units: fix parsing #8381

Closed
wants to merge 2 commits into from
Closed

systemd_units: fix parsing #8381

wants to merge 2 commits into from

Conversation

Mic92
Copy link
Contributor

@Mic92 Mic92 commented Nov 10, 2020

Required for all PRs:

  • Signed CLA.
  • Associated README.md updated.
  • Has appropriate unit tests.

Depending on the environment it may or not may contain unicode characters
@Mic92 Mic92 changed the title Systemd systemd_units Nov 10, 2020
@Mic92 Mic92 changed the title systemd_units systemd_units: fix parsing Nov 10, 2020
@Mic92
Copy link
Contributor Author

Mic92 commented Nov 10, 2020

It fixes this error:

Nov 10 10:05:40 rock telegraf[20327]: 2020-11-10T09:05:40Z E! [inputs.systemd_units] Error in plugin: Error parsing field 'load', value not in map: iscsi.service
Nov 10 10:05:40 rock telegraf[20327]: 2020-11-10T09:05:40Z E! [inputs.systemd_units] Error in plugin: Error parsing field 'load', value not in map: modprobe@drm.service
Nov 10 10:05:40 rock telegraf[20327]: 2020-11-10T09:05:40Z E! [inputs.systemd_units] Error in plugin: Error parsing field 'load', value not in map: nfs-server.service
Nov 10 10:05:40 rock telegraf[20327]: 2020-11-10T09:05:40Z E! [inputs.systemd_units] Error in plugin: Error parsing field 'load', value not in map: plymouth-quit-wait.service
Nov 10 10:05:40 rock telegraf[20327]: 2020-11-10T09:05:40Z E! [inputs.systemd_units] Error in plugin: Error parsing field 'load', value not in map: plymouth-quit.service
Nov 10 10:05:40 rock telegraf[20327]: 2020-11-10T09:05:40Z E! [inputs.systemd_units] Error in plugin: Error parsing field 'load', value not in map: plymouth-start.service
Nov 10 10:05:40 rock telegraf[20327]: 2020-11-10T09:05:40Z E! [inputs.systemd_units] Error in plugin: Error parsing field 'load', value not in map: rbdmap.service
Nov 10 10:05:40 rock telegraf[20327]: 2020-11-10T09:05:40Z E! [inputs.systemd_units] Error in plugin: Error parsing field 'load', value not in map: syslog.service
Nov 10 10:05:40 rock telegraf[20327]: 2020-11-10T09:05:40Z E! [inputs.systemd_units] Error in plugin: Error parsing field 'load', value not in map: systemd-hwdb-update.service
Nov 10 10:05:40 rock telegraf[20327]: 2020-11-10T09:05:40Z E! [inputs.systemd_units] Error in plugin: Error parsing field 'load', value not in map: systemd-sysusers.service

Comment on lines 154 to 157
// not found or failed units might have a leading asterisk
if data[0] == "*" {
data = data[1:]
}
Copy link
Member

@srebhan srebhan Nov 12, 2020

Choose a reason for hiding this comment

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

The problem is that we remove things after the length check. There might be cases where you get four fields, but an asterix in the beginning and then end up with only three fields left in data.

How about adding

Suggested change
// not found or failed units might have a leading asterisk
if data[0] == "*" {
data = data[1:]
}
if strings.HasPrefix(line, "*") {
line = strings.Replace(line, "*", "", 1)
}

above, directly after the assignment to line (line 148 I think) and before creating data?

Their first field will be an asteric:

$ LC_ALL=C systemctl list-units --all --type=service --no-legend
  accounts-daemon.service                               loaded    active   running Accounts Service
* acpid.service                                         not-found inactive dead    acpid.service
  alsa-store.service                                    loaded    active   exited  Store Sound Card State
* apparmor.service                                      not-found inactive dead    apparmor.service
  audio-off.service                                     loaded    active   exited  Mute audio before suspend
  audit.service                                         loaded    active   exited  Kernel Auditing
@srebhan
Copy link
Member

srebhan commented Nov 12, 2020

Does this also relate to issue #7990?

@ssoroka
Copy link
Contributor

ssoroka commented Nov 12, 2020

this might be resolved now as of #7991

@Mic92
Copy link
Contributor Author

Mic92 commented Nov 13, 2020

Yes.

@Mic92 Mic92 closed this Nov 13, 2020
@Mic92 Mic92 deleted the systemd branch November 13, 2020 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants