Commit 12ede5d01e623320b75533bf4b18ff36beb9ac69

Authored by Alexis Koralewski
1 parent fe47499e
Exists in dev

Add new field in cmd list (exec_time), fix issues with get_specific_cmds, try to…

… improve performance of js script in agent_detail view
src/core/pyros_django/api/serializers.py
... ... @@ -103,6 +103,12 @@ class AgentCmdSerializer(serializers.ModelSerializer):
103 103 class Meta:
104 104 model = AgentCmd
105 105 fields = "__all__"
  106 + exec_time = serializers.SerializerMethodField()
  107 + def get_exec_time(self,obj):
  108 + try:
  109 + return obj.r_end_time - obj.r_start_time
  110 + except:
  111 + return "None"
106 112  
107 113 class AgentSurveySerializer(serializers.ModelSerializer):
108 114 class Meta:
... ...
src/core/pyros_django/api/views.py
... ... @@ -278,7 +278,7 @@ class AgentCmdViewSet(viewsets.ModelViewSet):
278 278 commands_sent_by_agent = AgentCmd.get_commands_sent_by_agent(agent_name)
279 279 commands_recivied_by_agent = AgentCmd.get_commands_sent_to_agent(agent_name)
280 280 agent_cmds = commands_sent_by_agent | commands_recivied_by_agent
281   - agent_cmds = agent_cmds.exclude(full_name="get_specific_cmds")
  281 + #agent_cmds = agent_cmds.exclude(full_name="get_specific_cmds")
282 282 agent_cmds = agent_cmds.order_by("-s_deposit_time")
283 283 if number:
284 284 number = int(number)
... ...
src/core/pyros_django/dashboard/templates/dashboard/agent_detail.html
... ... @@ -30,6 +30,9 @@
30 30 .table{
31 31 width:auto;
32 32 }
  33 + .header{
  34 + text-align: center;
  35 + }
33 36 #overflowtable{
34 37 overflow-x: scroll;
35 38 }
... ... @@ -76,7 +79,7 @@
76 79 {% endfor %} {% endcomment %}
77 80 <div id="additional_fields" style="display:inline;"></div>
78 81 {% comment %} <input type="text" name="cmd_args" id="cmd_args"></input> {% endcomment %}
79   - <input type="submit" value="Send command"></input>
  82 + <input id="send_cmd_btn" type="submit" value="Send command"></input>
80 83 </form>
81 84 </div>
82 85 {% comment %} {% else %} {% endcomment %}
... ... @@ -90,7 +93,7 @@
90 93 {% endcomment %}
91 94  
92 95 <h2 id="cmd_unimplemented_message" style="color:red;"></h2>
93   - <h2 id="cmdform_exiting" style="color:red;"> {{ agent_name }} is not available.</h2>
  96 + <h2 id="cmdform_exiting" style="color:red;display:none" > {{ agent_name }} is not available.</h2>
94 97  
95 98 {% endif %}
96 99 {% if managed_agents != None %}
... ... @@ -165,12 +168,13 @@
165 168 <th>Sender</th>
166 169 <th>Recipient</th>
167 170 <th>Status </th>
168   - <th>Deposit (UTC)</th>
169   - <th>Read (UTC)</th>
170   - <th>Validity (s)</th>
171   - <th>Timeout (s)</th>
172   - <th>Exec start (UTC)</th>
173   - <th>Exec end (UTC)</th>
  171 + <th>Deposit<br> (UTC)</th>
  172 + <th>Read<br> (UTC)</th>
  173 + <th>Validity<br> (s)</th>
  174 + <th>Timeout<br> (s)</th>
  175 + <th>Exec start <br>(UTC)</th>
  176 + <th>Exec end <br>(UTC)</th>
  177 + <th>Exec time <br>(s)</th>
174 178 <th>Result</th>
175 179 </tr>
176 180 </thead>
... ... @@ -190,6 +194,7 @@
190 194 <td> [[ command.exec_timeout]] </td>
191 195 <td> [[ command.r_start_time]]</td>
192 196 <td> [[ command.r_end_time]]</td>
  197 + <td> [[ command.exec_time]]</td>
193 198 <td> [[ command.result ]] </td>
194 199 </tr>
195 200 </tbody>
... ... @@ -302,6 +307,9 @@
302 307 if (data != null && typeof data != "String"){
303 308 for(var arg of data){
304 309 var arg_name = arg[0];
  310 + if (arg_name == "<"){
  311 + return null;
  312 + }
305 313 var arg_type = arg[1];
306 314 if (arg_type == "str"){
307 315 var arg_type = "text";
... ... @@ -309,13 +317,19 @@
309 317 else if(arg_type == "int"){
310 318 var arg_type = "number";
311 319 }
312   -
313   - $("<label></label>").text(arg_name).appendTo("#additional_fields");
314   - $("<input type='text' value='' />")
315   - .attr("id", arg_name)
316   - .attr("name", arg_name)
317   - .attr("type",arg_type)
318   - .appendTo("#additional_fields");
  320 + if (arg_name == "U"){
  321 + $("<p></p>").text("This command isn't implemented").css("display","inline").appendTo("#additional_fields");
  322 + $("#send_cmd_btn").hide()
  323 + }else{
  324 + $("#send_cmd_btn").show()
  325 + $("<label></label>").text(arg_name).appendTo("#additional_fields");
  326 +
  327 + $("<input type='text' value='' />")
  328 + .attr("id", arg_name)
  329 + .attr("name", arg_name)
  330 + .attr("type",arg_type)
  331 + .appendTo("#additional_fields");
  332 + }
319 333 }
320 334 }
321 335 else{
... ... @@ -333,10 +347,10 @@
333 347 }
334 348 function display_form_cmd(status){
335 349 var cmdform = $("#cmdform")
336   - var cmdform_exitiing = $("#cmdform_exiting")
  350 + var cmdform_exiting = $("#cmdform_exiting")
337 351 if (status == "EXITING"){
338 352 if (cmdform.is(":visible")){
339   - cmdform_exitiing.show();
  353 + cmdform_exiting.show();
340 354 cmdform.hide();
341 355 }
342 356 }
... ... @@ -364,8 +378,8 @@
364 378 //$("#cmdform_running").append("</select>");
365 379 });
366 380 }
367   - if (cmdform_exitiing.is(":visible")){
368   - cmdform_exitiing.hide();
  381 + if (cmdform_exiting.is(":visible")){
  382 + cmdform_exiting.hide();
369 383 cmdform.show();
370 384 }
371 385 }
... ...
src/core/pyros_django/dashboard/views.py
... ... @@ -330,7 +330,7 @@ def agent_action(request):
330 330 else:
331 331 new_cmd = AgentCmd.send_cmd_from_to(request.user,agentsst,"do_restart_agent",recipient+ " hard")
332 332 elif action == "stop":
333   - new_cmd = AgentCmd.send_cmd_from_to(request.user,agentsst,"do_kill_agent",recipient)
  333 + new_cmd = AgentCmd.send_cmd_from_to(request.user,agentsst,"do_stop_agent",recipient)
334 334 if new_cmd != None:
335 335 messages.add_message(request, messages.INFO, f"Command sent !")
336 336 else:
... ...