Skip to content

Commit

Permalink
[script] implemented network interface cards info
Browse files Browse the repository at this point in the history
  • Loading branch information
MF Softworks committed Mar 15, 2019
1 parent 1fb6978 commit 02dd651
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 17 deletions.
Binary file added .vs/Server-Monitoring-Script/v15/.suo
Binary file not shown.
6 changes: 6 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ExpandedNodes": [
""
],
"PreviewInSolutionExplorer": false
}
Binary file added .vs/slnx.sqlite
Binary file not shown.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ The script will gather information:
- Hostname
- CPU
- Memory
- Network
- Network Usage
- Network Cards
- Hard Drives
- System OS
- System Uptime
Expand Down Expand Up @@ -54,6 +55,22 @@ Example:
],
"network_up": 54,
"network_down": 4150,
"network_cards": [
{
"address": "127.0.0.1",
"address6": "::1",
"mac": "",
"name": "Loopback Pseudo-Interface 1",
"netmask": "255.0.0.0"
},
{
"address": "10.15.62.112",
"address6": "fe80::844d:a87:54ea:2100",
"mac": "1C-39-47-A6-4C-5E",
"name": "Ethernet",
"netmask": "255.255.0.0"
}
],
"timestamp" : "2018-10-10T01:41:21+00:00",
"uuid" : 180331603484325
}
Expand Down
61 changes: 45 additions & 16 deletions monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,51 @@ def main():
print("Disks:")
disks = []
for x in disk_info:
disk = {
"name" : x.device,
"mount_point" : x.mountpoint,
"type" : x.fstype,
"total_size" : psutil.disk_usage(x.mountpoint).total,
"used_size" : psutil.disk_usage(x.mountpoint).used,
"percent_used" : psutil.disk_usage(x.mountpoint).percent
}

disks.append(disk)

print("\tDisk name",disk["name"], "\tMount Point:", disk["mount_point"], "\tType",disk["type"], "\tSize:", disk["total_size"] / 1e+9,"\tUsage:", disk["used_size"] / 1e+9, "\tPercent Used:", disk["percent_used"])

# Network Info
# Try fixes issues with connected 'disk' such as CD-ROMS, Phones, etc.
try:
disk = {
"name" : x.device,
"mount_point" : x.mountpoint,
"type" : x.fstype,
"total_size" : psutil.disk_usage(x.mountpoint).total,
"used_size" : psutil.disk_usage(x.mountpoint).used,
"percent_used" : psutil.disk_usage(x.mountpoint).percent
}

disks.append(disk)

print("\tDisk name",disk["name"], "\tMount Point:", disk["mount_point"], "\tType",disk["type"], "\tSize:", disk["total_size"] / 1e+9,"\tUsage:", disk["used_size"] / 1e+9, "\tPercent Used:", disk["percent_used"])
except:
print("")

# Bandwidth Info
network_stats = get_bandwidth()
print("Network:\n\tTraffic in:",network_stats["traffic_in"] / 1e+6,"\n\tTraffic out:",network_stats["traffic_out"] / 1e+6)

# Network Info
nics = []
print("NICs:")
for name, snic_array in psutil.net_if_addrs().items():
# Create NIC object
nic = {
"name": name,
"mac": "",
"address": "",
"address6": "",
"netmask": ""
}
# Get NiC values
for snic in snic_array:
if snic.family == -1:
nic["mac"] = snic.address
elif snic.family == 2:
nic["address"] = snic.address
nic["netmask"] = snic.netmask
elif snic.family == 23:
nic["address6"] = snic.address
nics.append(nic)
print("\tNIC:",nic["name"], "\tMAC:", nic["mac"], "\tIPv4 Address:",nic["address"], "\tIPv4 Subnet:", nic["netmask"], "\tIPv6 Address:", nic["address6"])

# Platform Info
system = {
"name" : platform.system(),
Expand Down Expand Up @@ -68,6 +96,7 @@ def main():
"drives" : disks,
"network_up" : network_stats["traffic_out"],
"network_down" : network_stats["traffic_in"],
"network_cards": nics,
"timestamp" : timestamp
}

Expand Down Expand Up @@ -108,7 +137,7 @@ def send_data(data):
try:
# endpoint = monitoring server
endpoint = "http://monitor.localhost.local/api/"
response = requests.post(url = endpoint, params = {"data" : data})
response = requests.post(url = endpoint, data = data)
print("\nPOST:")
print("Response:", response.status_code)
print("Headers:")
Expand All @@ -122,7 +151,7 @@ def send_data(data):
print("No JSON content")
break
except requests.exceptions.RequestException as e:
print("\POST Error:\n",e)
print("\nPOST Error:\n",e)
# Sleep 1 minute before retrying
time.sleep(60)
else:
Expand Down

0 comments on commit 02dd651

Please sign in to comment.