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

Plugin: openvpn #3424

Closed
faxm0dem opened this issue Mar 17, 2020 · 7 comments · Fixed by #3425
Closed

Plugin: openvpn #3424

faxm0dem opened this issue Mar 17, 2020 · 7 comments · Fixed by #3425

Comments

@faxm0dem
Copy link
Contributor

faxm0dem commented Mar 17, 2020

  • Version of collectd: master
  • Operating system / distribution: debian buster

Expected behavior

openvpn plugin should work even if it was configured not to assign ipv6 address

Actual behavior

It's failing with:

openvpn plugin: File format error in instance openvpn-status.log: Fields count mismatch.

Upon further investigation it appears that fields_num is 11 and columns 12 in openvpn.c line 376

Steps to reproduce

Configure openvpn so that ipv6 is empty

Here's an example status line:

TIME,Mon Mar 16 17:47:15 2020,1584377235
HEADER,CLIENT_LIST,Common Name,Real Address,Virtual Address,Virtual IPv6 Address,Bytes Received,Bytes Sent,Connected Since,Connected Since (time_t),Username,Client ID,Peer ID
CLIENT_LIST,jon-doe,1.2.3.4:50226,2.3.4.5,,105054404,148706903,Mon Mar 16 16:37:25 2020,1584373045,UNDEF,2145,0
HEADER,ROUTING_TABLE,Virtual Address,Common Name,Real Address,Last Ref,Last Ref (time_t)
ROUTING_TABLE,ff:ff:ff:ff:ff:ff,jon-doe,3.4.5.6:50226,Mon Mar 16 17:47:14 2020,1584377234
GLOBAL_STATS,Max bcast/mcast queue length,140
END
@faxm0dem
Copy link
Contributor Author

okay so the root cause is because strtok_r "skips" empty fields. From its manpage:

    From the above description, it follows that a sequence of  two  or  more
   contiguous  delimiter  bytes  in the parsed string is considered to be a
   single delimiter, and that delimiter bytes at the start or  end  of  the
   string  are  ignored.   Put another way: the tokens returned by strtok()
   are always nonempty  strings.   Thus,  for  example,  given  the  string
   "aaa;;bbb,",  successive  calls  to  strtok() that specify the delimiter
   string ";," would return the strings "aaa" and "bbb", and  then  a  null
   pointer.

@faxm0dem
Copy link
Contributor Author

it appears it's possible to use this trick, although it uses strtok and not strtok_r: https://stackoverflow.com/a/18827736/2122722

I would rather use strstep instead, but that might break other unices. Ideas?

@rpv-tomsk
Copy link
Contributor

Hi,

Stay tuned, WIP.

rpv-tomsk added a commit to rpv-tomsk/collectd that referenced this issue Mar 17, 2020
@faxm0dem
Copy link
Contributor Author

I tested this:

static int openvpn_strsplit(char *string, char **fields, size_t size) {
  size_t i = 0;
  char *ptr = string;

  while ((fields[i] = strsep(&ptr, ",\t")) != NULL) {
    i++;

    if (i >= size)
      break;
  }

  return i;
} /* int openvpn_strsplit */

@rpv-tomsk
Copy link
Contributor

Added #3425

@faxm0dem
Copy link
Contributor Author

is strsep available on solaris/AIX/etc.?

@dago
Copy link
Contributor

dago commented Mar 17, 2020

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 a pull request may close this issue.

3 participants