MCPcopy Create free account
hub / github.com/Icinga/icinga2 / WriteToFile

Method WriteToFile

lib/base/scriptglobal.cpp:83–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81}
82
83void ScriptGlobal::WriteToFile(const String& filename)
84{
85 Log(LogInformation, "ScriptGlobal")
86 << "Dumping variables to file '" << filename << "'";
87
88 AtomicFile fp (filename, 0600);
89 StdioStream::Ptr sfp = new StdioStream(&fp, false);
90
91 ObjectLock olock(m_Globals);
92 for (const Namespace::Pair& kv : m_Globals) {
93 Value value = kv.second.Val;
94
95 if (value.IsObject())
96 value = Convert::ToString(value);
97
98 Dictionary::Ptr persistentVariable = new Dictionary({
99 { "name", kv.first },
100 { "value", value }
101 });
102
103 String json = JsonEncode(persistentVariable);
104
105 NetString::WriteStringToStream(sfp, json);
106 }
107
108 sfp->Close();
109 fp.Commit();
110}

Callers

nothing calls this directly

Calls 4

LogClass · 0.85
IsObjectMethod · 0.80
CloseMethod · 0.45
CommitMethod · 0.45

Tested by

no test coverage detected