-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdaily-virus-scan.py
More file actions
executable file
·80 lines (64 loc) · 2.53 KB
/
Copy pathdaily-virus-scan.py
File metadata and controls
executable file
·80 lines (64 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#! /bin/bash/env python3
"""
The point of this script is to push out any postive virus scans
and to alert me via pushbullet notifications that would be sent
directly to my mobile device
"""
__author__ = """Reuben deVries"""
__version__ = """0.1"""
__date__ = """June 30, 2021"""
# importing built-in python modules
from logging import basicConfig, getLogger
from os import uname
from subprocess import run
# importing 3rd party python modules
from requests import post
# a function to start the logging process
def start_logging():
"""basic logging config - note where the log is stored, the time the event occured and the message."""
basicConfig(filename="/home/reuben/virus-scan.log",
format="%(asctime)s %(messages)s",
filemode="w",
level="WARN")
# starting the logger
logger = getLogger()
return logger # returning the logger so we can pass it to other functions.
def virus_scan(logger):
"""a function that will start a run a virus scan."""
logger()
results = run(["clamscan","--gen-json"])
print(results)
return results
# a function that will send a notification to my phone via pushbullet api.
def notify_me(logger, results): # inputs the virus count from below.
# Adding some variables for the function to work.
"""calling a OS environment variable that I've stored locally, ideally
I would like to find a better or more secure way to handle this
environment variable."""
logger()
api = ""
hostname = uname()[1] # Lets me know the hostname of the computer where the virus infection was found.
title = "Daily Clamscan Results on {0}".format(hostname) # The title of the message in the Pushbullet API Post.
data_send = {
"type": "note",
"title": title,
"body": results
} # What gets sent to Pushbullet API
response = post(
"https://api.pushbullet.com/v2/pushes",
data=data_send,
headers={
"Access-Token": api,
"Content-Type": "application/json"
}
)
status_code = response.status_code
if status_code != 200:
raise Exception("Something went wrong")
if __name__ == "__main__":
logger = start_logging
results = virus_scan(logger)
notify_me(logger, results)
#TODO list:
# Find a more secure way to handle the OS environment variable.
# add some proper error handling in the all of the functions