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

Include client summary (mloginfo --clients) #540

Closed
kallimachos opened this issue Nov 1, 2017 · 3 comments
Closed

Include client summary (mloginfo --clients) #540

kallimachos opened this issue Nov 1, 2017 · 3 comments

Comments

@kallimachos
Copy link
Collaborator

Logs contain a line:

NETWORK  [conn1] received client metadata from 127.0.0.1:50426 conn1: { application: { name: "MongoDB Shell" }, driver: { name: "MongoDB Internal Client", version: "3.4.10" }, os: { type: "Darwin", name: "Mac OS X", architecture: "x86_64", version: "16.7.0" } }

It would be good to have this OS and client information summarized as an option in mloginfo.

@niccottrell
Copy link

Agreed! How about a param --clients to output this data? Something like this (care of @garycahill):

import os
import sys

drivers = {}
check = True
file = sys.argv[1]

exists = os.path.isfile(file)
if exists:
    with open(file, 'rt') as myfile:
        for line in myfile:
            if line.lower().find("driver:") != -1:
                check = False
                if "mgo" not in line:
                    value_ip = line.split('metadata from ')[1].split(':', 1)[0]
                    version = line.split('version: "')[1].split('" },', 1)[0]
                    name = line.split('name: "')[1].split('"', 1)[0]
                    key_name_version = "|" + name + "|" + version + "|"
                    if key_name_version not in drivers:
                        drivers[key_name_version] = [value_ip]
                    elif key_name_version in drivers:
                        if value_ip in drivers.get(key_name_version):
                            continue
                        else:
                            drivers[key_name_version].append(value_ip)
                if "mgo" in line:
                    value_ip = line.split('metadata from ')[1].split(':', 1)[0]
                    key_name_version = "|mgo|globalsign|"
                    if key_name_version not in drivers:
                        drivers[key_name_version] = [value_ip]
                    elif key_name_version in drivers:
                        if value_ip in drivers.get(key_name_version):
                            continue
                        else:
                            drivers[key_name_version].append(value_ip)

    if check == True:
        print("No driver information found")
    else:
        print("|Driver|Version|Source IP|")
        print("|------|-------|---------|")
        for key, value in sorted(drivers.items()):
            print(key, str(value).replace("]", "|").replace("'","").replace("[",""))

else:
    print("File not found")

@stennie stennie added this to the 1.5.4 milestone May 27, 2019
@kallimachos
Copy link
Collaborator Author

I think a --clients option sounds good.

It probably makes sense to add it as a section file, similar to connection_section.py. Incidentally, that file also contains an example of how to use mloginfo.logfile and logevent to parse log lines, which saves writing some of the code in the example in the previous comment.

@niccottrell Would you be willing to open a PR for this?

@garycahill
Copy link
Contributor

I have added a pull request: #690
Using --clients displays driver name and version, along with each unique IP that initiated connection.
(Fairly new to github, apologies if I made any mistakes. )

@stennie stennie closed this as completed Dec 20, 2019
@stennie stennie changed the title Include client information summary in mloginfo Include client information summary (mloginfo --clients) Dec 27, 2019
@stennie stennie changed the title Include client information summary (mloginfo --clients) Include client summary (mloginfo --clients) Dec 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants