@@ -22,6 +22,8 @@ limitations under the License.
2222
2323#include < utility>
2424#include < filesystem>
25+ #include < fstream>
26+ #include < sstream>
2527#include < yaml-cpp/yaml.h>
2628#include < nlohmann/json.hpp>
2729
@@ -644,3 +646,52 @@ std::vector<std::unique_ptr<sinsp_filter_check>> plugin_utils::get_filterchecks(
644646 }
645647 return list;
646648}
649+
650+ bool plugin_utils::load_container_plugin_if_available (sinsp *inspector)
651+ {
652+ // Check if container plugin exists in any of the plugin directories
653+ std::string soname = SHAREDOBJ_PREFIX " container" SHAREDOBJ_EXT;
654+ bool plugin_exists = false ;
655+
656+ iterate_plugins_dirs (m_dirs, [&soname, &plugin_exists] (const std::filesystem::path file) -> bool {
657+ auto filename = file.filename ().generic_string ();
658+ if (filename == soname)
659+ {
660+ plugin_exists = true ;
661+ return true ; // break-out
662+ }
663+ return false ;
664+ });
665+
666+ if (!plugin_exists)
667+ {
668+ fprintf (stderr, " Warning: container plugin (%s) not found in plugin directories. Container metadata will not be available.\n " , soname.c_str ());
669+ fprintf (stderr, " This is expected if you're running sysdig standalone (not installed via package manager).\n " );
670+ return false ;
671+ }
672+
673+ try
674+ {
675+ // Load container configuration from file or use default
676+ std::string container_config = R"( {"hooks":["create","start"],"engines":{"docker":{"enabled":true,"sockets":["/var/run/docker.sock"]},"podman":{"enabled":true,"sockets":["/run/podman/podman.sock","/run/user/1000/podman/podman.sock"]},"containerd":{"enabled":false,"sockets":["/run/containerd/containerd.sock"]},"cri":{"enabled":true,"sockets":["/run/crio/crio.sock", "/run/containerd/containerd.sock"]},"lxc":{"enabled":false},"libvirt_lxc":{"enabled":false},"bpm":{"enabled":false}}})" ;
677+ auto container_config_file = " /etc/sysdig/container.json" ;
678+ if (std::filesystem::exists (container_config_file))
679+ {
680+ std::ifstream file (container_config_file);
681+ std::stringstream buffer;
682+ buffer << file.rdbuf ();
683+ container_config = buffer.str ();
684+ }
685+
686+ // Load and configure the plugin
687+ load_plugin (inspector, " container" );
688+ config_plugin (inspector, " container" , container_config);
689+ return true ;
690+ }
691+ catch (const sinsp_exception& e)
692+ {
693+ fprintf (stderr, " Warning: failed to load container plugin: %s\n " , e.what ());
694+ fprintf (stderr, " Container metadata will not be available.\n " );
695+ return false ;
696+ }
697+ }
0 commit comments