| 14 | using namespace icinga; |
| 15 | |
| 16 | Value VariableUtility::GetVariable(const String& name) |
| 17 | { |
| 18 | String varsfile = Configuration::VarsPath; |
| 19 | |
| 20 | std::fstream fp; |
| 21 | fp.open(varsfile.CStr(), std::ios_base::in); |
| 22 | |
| 23 | StdioStream::Ptr sfp = new StdioStream(&fp, false); |
| 24 | |
| 25 | String message; |
| 26 | StreamReadContext src; |
| 27 | for (;;) { |
| 28 | StreamReadStatus srs = NetString::ReadStringFromStream(sfp, &message, src); |
| 29 | |
| 30 | if (srs == StatusEof) |
| 31 | break; |
| 32 | |
| 33 | if (srs != StatusNewItem) |
| 34 | continue; |
| 35 | |
| 36 | Dictionary::Ptr variable = JsonDecode(message); |
| 37 | |
| 38 | if (variable->Get("name") == name) { |
| 39 | return variable->Get("value"); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | return Empty; |
| 44 | } |
| 45 | |
| 46 | void VariableUtility::PrintVariables(std::ostream& outfp) |
| 47 | { |
no test coverage detected