-
Notifications
You must be signed in to change notification settings - Fork 2
/
BigFixActioner.py
167 lines (147 loc) · 5.92 KB
/
BigFixActioner.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/local/autopkg/python
"""
BigFixActioner.py
"""
import chevron
from autopkglib import Processor, ProcessorError
from besapi import besapi
from BESImport import BESImport
__all__ = ["BigFixActioner"]
# noqa: B950
# if this template is used, you get an offer:
BES_SourcedFixletActionOffer = """\
<BES xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="BES.xsd">
<SourcedFixletAction>
<SourceFixlet>
<Sitename>{{bes_customsite}}</Sitename>
<FixletID>{{bes_id}}</FixletID>
<Action>{{bes_action}}</Action>
</SourceFixlet>
<Target>
<AllComputers>true</AllComputers>
</Target>
<Settings>
<PreActionShowUI>false</PreActionShowUI>
<HasRunningMessage>false</HasRunningMessage>
<HasTimeRange>false</HasTimeRange>
<HasStartTime>false</HasStartTime>
<HasEndTime>true</HasEndTime>
<EndDateTimeLocalOffset>P45D</EndDateTimeLocalOffset>
<HasDayOfWeekConstraint>false</HasDayOfWeekConstraint>
<UseUTCTime>false</UseUTCTime>
<ActiveUserRequirement>NoRequirement</ActiveUserRequirement>
<ActiveUserType>AllUsers</ActiveUserType>
<HasWhose>false</HasWhose>
<PreActionCacheDownload>false</PreActionCacheDownload>
<Reapply>true</Reapply>
<HasReapplyLimit>false</HasReapplyLimit>
<HasReapplyInterval>true</HasReapplyInterval>
<ReapplyInterval>PT15M</ReapplyInterval>
<HasRetry>true</HasRetry>
<RetryCount>99</RetryCount>
<RetryWait Behavior="WaitForReboot">PT1H</RetryWait>
<HasTemporalDistribution>false</HasTemporalDistribution>
<ContinueOnErrors>true</ContinueOnErrors>
<PostActionBehavior Behavior="Nothing"></PostActionBehavior>
<IsOffer>true</IsOffer>
<AnnounceOffer>false</AnnounceOffer>
<OfferCategory>Testing</OfferCategory>
<OfferDescriptionHTML><![CDATA[Offer to test automatically created content]]></OfferDescriptionHTML>
</Settings>
</SourcedFixletAction>
</BES>
"""
# if this template is used, you get an action:
BES_SourcedFixletAction = """\
<BES xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="BES.xsd">
<SourcedFixletAction>
<SourceFixlet>
<Sitename>{{bes_customsite}}</Sitename>
<FixletID>{{bes_id}}</FixletID>
<Action>{{bes_action}}</Action>
</SourceFixlet>
<Target>
<AllComputers>true</AllComputers>
</Target>
</SourcedFixletAction>
</BES>
"""
class BigFixActioner(BESImport):
"""AutoPkg Processor to create a BigFix action from imported content"""
description = __doc__
input_variables = {
"bes_id": {
"required": False,
"default": 0,
"description": "ID of the Fixlet or Task to Action",
},
"bes_customsite": {
"required": False,
"default": "autopkg",
"description": "BES console custom site to find the Task or Fixlet within.",
},
"bes_action": {
"required": False,
"default": "Action1",
"description": "Which Action to run",
},
"bes_action_type": {
"required": False,
"default": "Offer",
"description": "Tells autopkg to create an action or offer.",
},
}
output_variables = {
"bes_action_id": {
"description": "The returned ID of the bigfix action created."
},
"bigfix_actioner_summary_result": {
"description": "Description of BigFix Actioner results."
},
}
__doc__ = description
def main(self):
"""BigFixActioner Main Method"""
template_dict = {}
template_dict["bes_id"] = self.env.get("bes_id", 0)
bes_action_type = str(self.env.get("bes_action_type", "Offer"))
if template_dict["bes_id"] == 0:
self.output("Nothing to action.", 0)
else:
self.get_config()
template_dict["bes_customsite"] = self.env.get("bes_customsite", "autopkg")
template_dict["bes_action"] = self.env.get("bes_action", "Action1")
BES_USERNAME = self.env.get("BES_USER_NAME")
BES_PASSWORD = self.env.get("BES_PASSWORD")
BES_ROOT_SERVER = self.env.get("BES_ROOT_SERVER")
# clear password from ENV
self.env["BES_PASSWORD"] = ""
if "action" in bes_action_type.lower():
bes_action_data = chevron.render(BES_SourcedFixletAction, template_dict)
else:
bes_action_data = chevron.render(
BES_SourcedFixletActionOffer, template_dict
)
self.output(bes_action_data, 4)
# BigFix Server Connection
# https://github.com/jgstew/besapi/blob/master/src/besapi/besapi.py
bes_conn = besapi.BESConnection(
BES_USERNAME, BES_PASSWORD, BES_ROOT_SERVER, verify=False
)
action_result = bes_conn.post("actions", bes_action_data)
self.output(action_result, 2)
# self.env["bes_action_id"] = ""
if action_result:
self.env["bes_action_id"] = str(action_result().Action.ID)
# Create summary result data
self.env["bigfix_actioner_summary_result"] = {
"summary_text": "The following actions were created in BigFix:",
"report_fields": ["Action ID", "Action Name"],
"data": {
"Action ID": str(action_result().Action.ID),
"Action Name": str(action_result().Action.Name),
},
}
if __name__ == "__main__":
processor = BigFixActioner()
processor.execute_shell()