Repository navigation
Expand file tree
/
Copy pathyardPrinters.py
More file actions
127 lines (107 loc) · 3.67 KB
/
Copy pathyardPrinters.py
File metadata and controls
127 lines (107 loc) · 3.67 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
from multiprocessing import Pool
import multiprocessing as mp
import pandas as pd
import time
import os
import re
brands = []
cmds = []
counter = 0
toaster = ToastNotifier()
df = pd.read_excel('yardPrinterIP.xlsx', sheet_name = 'Sheet1')
def ricohToners(cmd, ip, location):
#Reads Black toner levels
black = os.popen(cmd + " 1.3.6.1.2.1.43.11.1.1.9.1.1").read()
bLevel = re.sub("[^0-9]", "", black[-4:-1])
if str(black):
#Checks if printer is a color printer
cyan = os.popen(cmd + " 1.3.6.1.2.1.43.11.1.1.9.1.3").read()
cLevel = re.sub("[^0-9]", "", cyan[-4:-1])
if str(cyan):
#Read remaining toner levels if it is a color printer
magenta = os.popen(cmd + " 1.3.6.1.2.1.43.11.1.1.9.1.4").read()
mLevel = re.sub("[^0-9]", "", magenta[-4:-1])
yellow = os.popen(cmd + " 1.3.6.1.2.1.43.11.1.1.9.1.5").read()
yLevel = re.sub("[^0-9]", "", yellow[-4:-1])
#Prints to command line if the toner levels are below 10%
if int(bLevel) < 10:
text = "Black is low/empty at " + ip + " " + location
print(text)
if int(cLevel) < 10:
text = "Cyan is low/empty at " + ip + " " + location
print(text)
text = "Magenta is low/empty at " + ip + " " + location
print(text)
if int(yLevel) < 10:
text = "Yellow is low/empty at " + ip + " " + location
print(text)
else:
if int(bLevel) < 10:
text = "Black is low/empty at " + ip + " " + location
print(text)
else:
text = "Check " + ip + " " + location
print(text)
def hpToners(cmd, ip, location):
#Reads Black toner levels and toner type
black = os.popen(cmd + " 1.3.6.1.2.1.43.11.1.1.9.1.1").read()
bLevel = re.sub("[^0-9]", "", black[-4:-1])
order = os.popen(cmd + " 1.3.6.1.2.1.43.11.1.1.6.1.1").read()
order = order[-6:-2]
if str(black):
#Checks if printer is a color printer
cyan = os.popen(cmd + " 1.3.6.1.2.1.43.11.1.1.9.1.2").read()
cLevel = re.sub("[^0-9]", "", cyan[-4:-1])
if str(cyan):
#Read remaining toner levels if it is a color printer
magenta = os.popen(cmd + " 1.3.6.1.2.1.43.11.1.1.9.1.3").read()
mLevel = re.sub("[^0-9]", "", magenta[-4:-1])
yellow = os.popen(cmd + " 1.3.6.1.2.1.43.11.1.1.9.1.4").read()
yLevel = re.sub("[^0-9]", "", yellow[-4:-1])
#Prints to command line with toner type if the toner levels are below 10%
if int(bLevel) < 10:
text = "Black is low/empty at " + ip + " " + location + "\n" + order
print(text)
if int(cLevel) < 10:
text = "Cyan is low/empty at " + ip + " " + location + "\n" + order
print(text)
if int(mLevel) < 10:
text = "Magenta is low/empty at " + ip + " " + location + "\n" + order
print(text)
if int(yLevel) < 10:
text = "Yellow is low/empty at " + ip + " " + location + "\n" + order
print(text)
else:
if int(bLevel) < 10:
text = "Black is low/empty at " + ip + " " + location + "\n" + order
print(text)
else:
text = "Check " + ip + " " + location
print(text)
def main(cmds):
cmd = cmds[0]
i = cmds[1]
brands = cmds[2]
#Checks to see if printer is a Ricoh or an HP printer
if brands == 'Ricoh':
ricohToners(cmd, str(df['IP'][i]), str(df['Location'][i]))
elif brands == 'HP':
hpToners(cmd, str(df['IP'][i]), str(df['Location'][i]))
if __name__ == "__main__":
startTime = time.time()
for i in df.index:
brands.append(df['Brand'][i])
ip = df['IP'][i]
if brands[i] == 'Ricoh':
cmd = "snmpwalk -v1 -c public " + ip
cmds.append([cmd, counter, str(brands[i])])
elif brands[i] == 'HP':
cmd = "snmpwalk -v1 -c public " + ip
cmds.append([cmd, counter, str(brands[i])])
counter += 1
with Pool(mp.cpu_count()) as p:
records = p.map(main, cmds)
p.terminate()
p.join()
print("Finished")
print("--- %s seconds ---" % (time.time() - startTime))