9.5.5. plugins/plugin_patch2.pyΒΆ

  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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
from collections import OrderedDict

VERSION = "1.1.0"
"""Version of this set of plugin definitions."""

MINIMUM_THAT_VERSION = "1.1.0"
"""Minimum THAT version required to run these plugin definitions."""

NAME = "patch2"
PRIORITY = 8
ANALYZE_DATA = OrderedDict()
GET_TANIUM_DATA = OrderedDict()

GET_INTERNET_DATA = [
]

# ask the question 'Get Patch - Is Process Running from all machines'
# and store results in "patch2running.csv"
GET_TANIUM_DATA["patch2running.csv"] = {
    "filters": [],
    "sensors": ["Patch - Is Process Running"],
}

# ask the question 'Get Applicable Patches from all machines'
# and store results in "patch2patches.csv"
GET_TANIUM_DATA["patch2patches.csv"] = {
    "filters": [],
    "sensors": ["Applicable Patches"],
}

# ask the question 'Get Reboot Required from all machines'
# and store results in "patch2reboot.csv"
GET_TANIUM_DATA["patch2reboot.csv"] = {
    "filters": [],
    "sensors": ["Reboot Required"],
}


ANALYZE_DATA["extra_clean_values"] = """
# set extra clean values to be used for df cleaning
result = ["Scan Error", "N/A on Mac", "N/A on Solaris", "N/A on Linux", "N/A on AIX", "Unable to load PatchLib"]
"""

ANALYZE_DATA["cleaned_patch2running_df"] = """
# clean out noise from patch2running.csv

csv = "patch2running.csv"
df = self.load_csv_as_df(csv)
extra_clean_values = self.get_result("extra_clean_values")

result = self.clean_df(df, columns=["Patch - Is Process Running"], add_values=extra_clean_values)
"""

ANALYZE_DATA["cleaned_patch2patches_df"] = """
# clean out noise from patch2patches.csv

csv = "patch2patches.csv"
df = self.load_csv_as_df(csv)
extra_clean_values = self.get_result("extra_clean_values")

result = self.clean_df(df, columns=["Title"], add_values=extra_clean_values)
"""

ANALYZE_DATA["cleaned_patch2reboot_df"] = """
# clean out noise from patch2reboot.csv

csv = "patch2reboot.csv"
df = self.load_csv_as_df(csv)
extra_clean_values = self.get_result("extra_clean_values")

result = self.clean_df(df, columns=["Reboot Required"], add_values=extra_clean_values)
"""

ANALYZE_DATA["patch2_total_targets"] = """
# Is running Patch2 Process

df = self.get_result("cleaned_patch2running_df")

result = df.loc[df['Patch - Is Process Running'] == 'Yes', 'Count'].sum()
"""

ANALYZE_DATA["patch2_any_patch_count"] = """
# Total Number of Missing Patches (Any Severity)

df = self.get_result("cleaned_patch2patches_df")

result = df['Title'].count()
"""

ANALYZE_DATA["patch2_critical_patch_count"] = """
# Total Number of Missing Patches (Critical Severity)

df = self.get_result("cleaned_patch2patches_df")

result = df.loc[df['Severity'] == 'Critical', 'Title'].count()
"""

ANALYZE_DATA["patch2_any_req_patch"] = """
# Total Required Patches Across Endpoints (Any Severity)

df = self.get_result("cleaned_patch2patches_df")

result = df['Count'].sum()
"""

ANALYZE_DATA["patch2_critical_req_patch"] = """
# Total Required Patches Across Endpoints (Critical Severity)

df = self.get_result("cleaned_patch2patches_df")

result = df.loc[df['Severity'] == 'Critical', 'Count'].sum()
"""

ANALYZE_DATA["patch2_any_req_patch_avg"] = """
# Average Number of Missing Patch Installations per Endpoint (Any Severity)

df = self.get_result("cleaned_patch2patches_df")
total_missing_patches = df['Count'].sum()

df = self.get_result("cleaned_patch2running_df")
total_endpoints = df.loc[df['Patch - Is Process Running'] == 'Yes', 'Count'].sum()

result = math.ceil( total_missing_patches / total_endpoints )
"""

ANALYZE_DATA["patch2_oldest_patch"] = """
# Oldest Date Any Severity Patch

df = self.get_result("cleaned_patch2patches_df")

result = pandas.to_datetime(df['Release Date'], errors='coerce').min().strftime('%m/%d/%Y')
"""

ANALYZE_DATA["patch2_msft_prod_affected"] = """
# Approximate Number of Products Affected (Unique Product Count)

df = self.get_result("cleaned_patch2patches_df")

result = len(df['Files'].str.replace('\\\\-kb.*', '').unique())
"""

ANALYZE_DATA["patch2_reboot_req"] = """
# Reboot Required

df = self.get_result("cleaned_patch2reboot_df")

result = df.loc[df['Reboot Required'] == 'Yes', 'Count'].sum()
"""