Skip to content

add disable_sudo_conntrack option for network integration#4746

Closed
stonith wants to merge 1 commit into
DataDog:masterfrom
stonith:no_sudo_docker
Closed

add disable_sudo_conntrack option for network integration#4746
stonith wants to merge 1 commit into
DataDog:masterfrom
stonith:no_sudo_docker

Conversation

@stonith

@stonith stonith commented Oct 11, 2019

Copy link
Copy Markdown

What does this PR do?

Add disable_sudo_conntrack option to disable sudo when running conntrack -S

Motivation

sudo is generally not available in containers and conntrack can be run without it

Review checklist (to be filled by reviewers)

  • PR title must be written as a CHANGELOG entry (see why)
  • Files changes must correspond to the primary purpose of the PR as described in the title (small unrelated changes should have their own PR)
  • PR must have changelog/ and integration/ labels attached
  • Feature or bugfix must have tests
  • Git history must be clean
  • If PR adds a configuration option, it must be added to the configuration file.

@stonith
stonith requested review from a team as code owners October 11, 2019 06:23
Comment thread network/datadog_checks/network/network.py Outdated
@stonith stonith changed the title run conntrack without sudo when in docker container add disable_sudo_conntrack option for network integration Oct 11, 2019
@stonith
stonith force-pushed the no_sudo_docker branch 2 times, most recently from a842290 to 3436430 Compare October 11, 2019 23:27
@hithwen

hithwen commented Oct 15, 2019

Copy link
Copy Markdown
Contributor

Hallo, thanks for addressing the comments. We are currently on a code freeze but we'll come back as soon as its over.

@therve therve left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for your patch, some minor comments.


# Get the conntrack -S information
conntrack_path = instance.get('conntrack_path')
disable_sudo_conntrack = instance.get('disable_sudo_conntrack', False)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
disable_sudo_conntrack = instance.get('disable_sudo_conntrack', False)
disable_sudo_conntrack = is_affirmative(instance.get('disable_sudo_conntrack', False))

if disable_sudo_conntrack is True:
output, _, _ = get_subprocess_output([conntrack_path, "-S"], self.log)
else:
output, _, _ = get_subprocess_output(["sudo", conntrack_path, "-S"], self.log)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd write it a bit differently:

cmd = [conntrack_path, "-S"]
if use_sudo:
    cmd.insert(0, "sudo")
output, _, _ = get_subprocess_output(cmd, self.log)

And then pass not disable_sudo_contrack as argument instead.

@ChristineTChen

Copy link
Copy Markdown
Contributor

Hi @stonith, thank you for your contribution! Closed in favor of #4920 with updated feedback. 😄

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.

4 participants