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

Method WriteNodeConfigObjects

lib/cli/nodeutility.cpp:146–182  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

144}
145
146bool NodeUtility::WriteNodeConfigObjects(const String& filename, const Array::Ptr& objects)
147{
148 Log(LogInformation, "cli")
149 << "Dumping config items to file '" << filename << "'.";
150
151 /* create a backup first */
152 CreateBackupFile(filename);
153
154 String path = Utility::DirName(filename);
155
156 Utility::MkDirP(path, 0755);
157
158 String user = Configuration::RunAsUser;
159 String group = Configuration::RunAsGroup;
160
161 if (!Utility::SetFileOwnership(path, user, group)) {
162 Log(LogWarning, "cli")
163 << "Cannot set ownership for user '" << user << "' group '" << group << "' on path '" << path << "'. Verify it yourself!";
164 }
165
166 AtomicFile fp (filename, 0644);
167
168 fp << "/*\n";
169 fp << " * Generated by Icinga 2 node setup commands\n";
170 fp << " * on " << Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", Utility::GetTime()) << "\n";
171 fp << " */\n\n";
172
173 ObjectLock olock(objects);
174 for (Dictionary::Ptr object : objects) {
175 SerializeObject(fp, object);
176 }
177
178 fp << std::endl;
179 fp.Commit();
180
181 return true;
182}
183
184
185/*

Callers

nothing calls this directly

Calls 5

LogClass · 0.85
DirNameFunction · 0.85
MkDirPFunction · 0.85
SerializeObjectFunction · 0.85
CommitMethod · 0.45

Tested by

no test coverage detected