Skip to content

Commit

Permalink
Added code to get company name and server version.
Browse files Browse the repository at this point in the history
Signed-off-by: sreepuramsudheer <ssudheer@progress.com>
  • Loading branch information
sreepuramsudheer committed Jun 13, 2024
1 parent 572384a commit e567bce
Showing 1 changed file with 44 additions and 18 deletions.
62 changes: 44 additions & 18 deletions src/oc_erchef/apps/chef_telemetry/src/chef_telemetry_worker.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

-behaviour(gen_server).

-include("../../../include/chef_types.hrl").

-export([
start_link/0,
solr_search/1
Expand Down Expand Up @@ -52,24 +54,11 @@ handle_call(_Message, _From, State) ->
{noreply, State}.

handle_cast(send_data, State) ->
% code to get chef_server version.
[{_Server, _ServerVersion, _}] = release_handler:which_release(permanent),
ReqId = base64:encode(term_to_binary(make_ref())),
EpochNow = erlang:system_time(seconds),
TimeDuration = ?DEFAULT_DAYS * 86400,
Epoch30DaysOld = EpochNow - TimeDuration,
QueryString = lists:flatten(io_lib:format("ohai_time:{~p TO ~p}", [Epoch30DaysOld, EpochNow])),
Query1 = chef_index:query_from_params("node", QueryString, undefined, undefined),
DbContext = chef_db:make_context("1.0", ReqId, false),
_Count =
case chef_db:count_nodes(DbContext) of
Count1 when is_integer(Count1) -> Count1;
Error -> throw({db_error, Error})
end,
Orgs =
case chef_db:list(#oc_chef_organization{}, DbContext) of
Orgs1 when is_list(Orgs1) -> Orgs1;
Error1 -> throw({db_error, Error1})
end,
_Stats = [ {Org, get_org_nodes(Org, Query1, ReqId, DbContext)} || Org <- Orgs ],
_Stats = get_nodes(ReqId),
_companyName = get_company_name(),
% sending data logic hear
gen_server:cast(self(), init_timer),
{noreply, State};
Expand Down Expand Up @@ -130,4 +119,41 @@ solr_search(Query) ->
catch
Error:Reason ->
{Error, Reason}
end.
end.

get_company_name() ->
case sqerl:adhoc_select([email], users, all, []) of
{ok, Ids1} ->
Ids = [Id || [{_, Id}] <- Ids1],
Fun =
fun(Email) ->
case re:run(Email, "^[^@]*@\([^.]*\)\..*$") of
{match, [_, {Pos, Len} | _]} ->
{true, binary:part(Email, Pos, Len)};
_ ->
false
end
end,
binary_to_list(lists:head(lists:filtermap(Fun, Ids)));
Error ->
throw(Error)
end.

get_nodes(ReqId) ->
EpochNow = erlang:system_time(seconds),
TimeDuration = ?DEFAULT_DAYS * 86400,
Epoch30DaysOld = EpochNow - TimeDuration,
QueryString = lists:flatten(io_lib:format("ohai_time:{~p TO ~p}", [Epoch30DaysOld, EpochNow])),
Query1 = chef_index:query_from_params("node", QueryString, undefined, undefined),
DbContext = chef_db:make_context("1.0", ReqId, false),
_Count =
case chef_db:count_nodes(DbContext) of
Count1 when is_integer(Count1) -> Count1;
Error -> throw({db_error, Error})
end,
Orgs =
case chef_db:list(#oc_chef_organization{}, DbContext) of
Orgs1 when is_list(Orgs1) -> Orgs1;
Error1 -> throw({db_error, Error1})
end,
_Stats = [ {Org, get_org_nodes(Org, Query1, ReqId, DbContext)} || Org <- Orgs ].

0 comments on commit e567bce

Please sign in to comment.