Skip to content

Commit 05dd7b9

Browse files
author
Bryan Worrell
committed
Added campaign reference example
1 parent fcf1ff5 commit 05dd7b9

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

examples/campaign-reference.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env python
2+
# Copyright (c) 2015, The MITRE Corporation. All rights reserved.
3+
# See LICENSE.txt for complete terms.
4+
5+
"""
6+
Demonstrates the methods for adding related Campaign references to an
7+
Indicator object.
8+
"""
9+
10+
from stix.core import STIXPackage
11+
from stix.common import CampaignRef
12+
from stix.campaign import Campaign
13+
from stix.indicator import Indicator
14+
15+
16+
def main():
17+
# Build Campaign instances
18+
camp1 = Campaign(title='Campaign 1')
19+
camp2 = Campaign(title='Campaign 2')
20+
21+
# Build a CampaignRef object, setting the `idref` to the `id_` value of
22+
# our `camp2` Campaign object.
23+
campaign_ref = CampaignRef(idref=camp2.id_)
24+
25+
# Build an Indicator object.
26+
i = Indicator()
27+
28+
# Add CampaignRef object pointing to `camp2`.
29+
i.add_related_campaign(campaign_ref)
30+
31+
# Add Campaign object, which gets promoted into an instance of
32+
# CampaignRef type internally. Only the `idref` is set.
33+
i.add_related_campaign(camp1)
34+
35+
# Build our STIX Package and attach our Indicator and Campaign objects.
36+
package = STIXPackage()
37+
package.add_indicator(i)
38+
package.add_campaign(camp1)
39+
package.add_campaign(camp2)
40+
41+
# Print!
42+
print package.to_xml()
43+
44+
if __name__ == "__main__":
45+
main()

0 commit comments

Comments
 (0)