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

Script which can convert existing bots in the group collector to Systemd services #953

Closed
wants to merge 18 commits into from

Conversation

navtej
Copy link
Contributor

@navtej navtej commented Apr 21, 2017

Title says it all. However this is a hackish script. For those who know what they are doing.

@codecov-io
Copy link

codecov-io commented Apr 21, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@a63b205). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #953   +/-   ##
=========================================
  Coverage          ?   77.98%           
=========================================
  Files             ?      221           
  Lines             ?     9047           
  Branches          ?        0           
=========================================
  Hits              ?     7055           
  Misses            ?     1992           
  Partials          ?        0

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a63b205...fce070e. Read the comment docs.

import shutil

INTELMQ_DIR = '/opt/intelmq'
RUNTIME_CONF = INTELMQ_DIR+'/etc/runtime.conf'
Copy link

@ghost ghost Apr 24, 2017

Choose a reason for hiding this comment

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

This is in intelmq.RUNTIME_CONF_FILE


INTELMQ_DIR = '/opt/intelmq'
RUNTIME_CONF = INTELMQ_DIR+'/etc/runtime.conf'
PIPELINE_CONF = INTELMQ_DIR+'/etc/pipeline.conf'
Copy link

Choose a reason for hiding this comment

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

Is in intelmq.PIPELINE_CONF_FILE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did not imported intelmq, perhaps will be a good idea to do that.

@ghost ghost self-requested a review April 24, 2017 10:26
@ghost ghost added this to the v1.1 Feature release milestone Apr 24, 2017
@navtej
Copy link
Contributor Author

navtej commented Apr 24, 2017

This needs a lot more testing. I have tested it only on one OS. Will be great if more folks can test it out on other systems.

# Return only the bots which are directly connected
# If a bot has more than one inputs or outputs stop processing
#
def connected_bots(bot,rc_data,pipe_data):
Copy link

Choose a reason for hiding this comment

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

That's not used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know. Not as of now, I am still trying to make the directly connected units (as explained in mailing list) work as connected systemd scripts. So can we please keep these? Unfortunately i cannot commit to any timeline, atleast this week looks pretty busy.

DISABLE_IN_CONF = True
SET_RUNMODE_IN_CONF = True
INTELMQCTL_BIN = shutil.which('intelmqctl')
SYSTEMCTL_BIN = shutil.which('systemctl')
Copy link

Choose a reason for hiding this comment

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

never used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SYSTEMCTL_BIN is the only one which is never used, however it was used for making other units trigger after the collector.

tmr_file.write(timer_data)

if DISABLE_IN_CONF or SET_RUNMODE_IN_CONF:
shutil.move(RUNTIME_CONF, RUNTIME_CONF+'.bak')
Copy link

Choose a reason for hiding this comment

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

if you copy here, you do not need to fix the permissions afterwards

@ghost
Copy link

ghost commented Apr 25, 2017

I pushed a commit with a bunch of style fixes

shutil.move(RUNTIME_CONF_FILE, RUNTIME_CONF_FILE + '.bak')
rc_data = collections.OrderedDict(sorted(rc_data.items()))
data = json.dumps(rc_data, indent=4)
with open(RUNTIME_CONF_FILE, "w", encoding='utf-8') as rc_file:
Copy link

Choose a reason for hiding this comment

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

You can reuse intelmqctl's write_updated_runtime_config here.

@ghost
Copy link

ghost commented Apr 25, 2017

You are assuming that all collectors should be scheduled, but stream collectors (http stream, n6, xmpp, alienvault otx) can't run in this mode properly.

@navtej
Copy link
Contributor Author

navtej commented May 5, 2017

I understand, however , I am unable to find a good solution to it, couple of things I can think of

  1. Let the user mark the bot's run_mode and only convert scheduled bots to services?
  2. Take bot IDs as command line arguments, and convert those to services.

2 can then have web UI page to automate the work.
I might not be able to work on these for few days.

@navtej
Copy link
Contributor Author

navtej commented May 31, 2017

partially addresses the problem of selectively scheduling the bots. Unless there is a way to figure out which bots can be scheduled, there doesn't seems to be any decent way out of it.

@ghost ghost added the feature Indicates new feature requests or new features label Jun 14, 2017
@ghost ghost changed the base branch from master to develop July 5, 2017 15:37
@ghost ghost self-assigned this Sep 28, 2017
@ghost
Copy link

ghost commented Jan 31, 2018

Could you reduce the number of tiny commits here (these "wip" and similar) please? Then I'll merge this and afterwards open a PR adding support for continuous collectors and some other fixes.

@ghost ghost added the needs: feedback label Feb 22, 2018
@ghost ghost closed this in 8680414 Jun 15, 2018
@ghost
Copy link

ghost commented Jun 15, 2018

Squashed the commits now on my own and merged it finally, also with some extensions and fixes by me (see 83bef55 c3ec3c6 and 543d736)

@ghost ghost removed the needs: feedback label Jun 15, 2018
@navtej
Copy link
Contributor Author

navtej commented Jun 15, 2018

Thanks. Sorry for be being too late, I have been pulled into too many things.

@ghost
Copy link

ghost commented Jun 15, 2018

I have been pulled into too many things.

#metoo ;)

Cleaning up now to get the next feature release ready :)

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: contrib component: process management feature Indicates new feature requests or new features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants