Asterisk AMI API UpdateConfig Action Issue

Hello, I am attempting to use the Asterisk Manager API to update a configuration file using the UpdateConfig Action. When doing so I am repeatedly getting an error response of “Message: Save of config failed”. Below is a PHP code snippet and if anyone can add some suggestions as to what may be going wrong it would greatly appreciated. On a side note I regularly use the AMI API for other functions so I know that it is working.

// Login
$socket = fsockopen($domain, 5038, $errno, $errstr, 30);
fputs($socket, “Action: Login\r\n”);
fputs($socket, “Username: “.$username.”\r\n”);
fputs($socket, “Secret: “.$secret.”\r\n\r\n”);
$wrets = fread($socket, 8192);
echo $wrets;

// Update Config
fputs($socket, “Action: UpdateConfig\r\n”);
fputs($socket, “Reload: no\r\n”); // No for testing but will be Yes.
fputs($socket, “Srcfilename: pjsip.auth.conf\r\n”);
fputs($socket, “Dstfilename: /tmp/pjsip.test.conf\r\n”); // Just a temp location to see if things work
fputs($socket, “Action-000000: update\r\n”);
fputs($socket, “Cat-000000: 10000-auth\r\n”);
fputs($socket, “Var-000000: password\r\n”);
fputs($socket, “Value-000000: 1234\r\n\r\n”);
$wrets = fread($socket, 8192);
echo $wrets;

// Logoff
fputs($socket, “Action: Logoff\r\n\r\n”);
$wrets = fread($socket, 8192);
fclose($socket);
echo $wrets;

Try to save your destination file in /etc/asterisk.

I havent use UpdateConfig action, but did you make sure it is not permision issue ?

Thanks for the ideas guys. Its not the path or permissions but good thinking.

Most likely @ambiorixg12 is right, but I’ll use the Asterisk source code to back me up a bit on that assertion.

If we look at the relevant bits of action_updateconfig, which handles the UpdateConfig action, you’ll see that the function that actually saves the configuration changes is ast_config_text_file_save2, the result of which - if non-zero - causes the error message you’re getting back from AMI:

	res = ast_config_text_file_save2(dfn, cfg, "Manager", preserve_effective_context);
	ast_config_destroy(cfg);
	if (res) {
		astman_send_error(s, m, "Save of config failed");
		return 0;
	}

Now, there’s actually a lot of ways this can fail. However, if you’re providing a valid config file name, and if that file exists in the expected configuration file directory path, then the most likely failure is a permissions issue. That aside, the Asterisk CLI should be dumping out an ERROR message indicating exactly why the configuration file can’t be saved. Most likely, one of the following:

ast_log(LOG_ERROR, "Unable to write to directory %s (%s)\n", dn, strerror(errno));

or

ast_log(LOG_ERROR, "Unable to write %s (%s)\n", fn, strerror(errno));

So - do you see anything on the CLI when the AMI action fails? If so, which ERROR message do you see? If not, can you provide the CLI output - with VERBOSE set to 5? That should give enough information to figure out why the action is failing.

1 Like

Great explanation @mjordan I hope we can get more feedbacks like that, from the Asterisk core developer team

Hi Guys, it did turn out to be a permission issue. I really appreciate all your expertise with this matter.